2

I have a string like this

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

I would like the pattern match ["password"] = and have it replace only the string in between the ";' that would be '"krghfkghkfghf" in this instance.

finnw
  • 47,861
  • 24
  • 143
  • 221
Joseph Philbert
  • 635
  • 7
  • 8

2 Answers2

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

That won't work if your password contains a double quote inside.

W.B.
  • 5,445
  • 19
  • 29
-1

i have same question as well, how about the following password replace ?

"password" : "krghfkghkfghf"
wesleylim1993
  • 51
  • 2
  • 2
  • 8