2

我有一个这样的字符串

     str = '["username"] = "user";
     ["deepscan"] = "true";
     ["token"] = true;
     ["password"] = "krghfkghkfghf";
     ["uploadMethod"] = "JSON";
     ["serviceIsRunning"] = {};
     ["host"] = "sample.com";
     ["instance_ID"] = 405454058;'

在这种情况下,我想要模式匹配 ["password"] =并让它只替换介于两者之间的字符串。";' that would be '"krghfkghkfghf"

4

2 回答 2

1
local function replacePass(configstr, newpass)
    return configstr:gsub("(%[\"password\"%]%s*=%s*)%b\"\"", "%1\"" .. newpass .. "\"")
end

如果您的密码中包含双引号,那将不起作用。

于 2013-05-19T20:04:39.390 回答
0

我也有同样的问题,下面的密码替换怎么样?

"password" : "krghfkghkfghf"
于 2020-05-25T05:19:06.560 回答