string substitution - Replace a substring in Lua with a pattern -
i have string
str = '["username"] = "user"; ["deepscan"] = "true"; ["token"] = true; ["password"] = "krghfkghkfghf"; ["uploadmethod"] = "json"; ["serviceisrunning"] = {}; ["host"] = "sample.com"; ["instance_id"] = 405454058;'
i pattern match ["password"] =
, have replace string in between ";' '"krghfkghkfghf"
in instance.
local function replacepass(configstr, newpass) return configstr:gsub("(%[\"password\"%]%s*=%s*)%b\"\"", "%1\"" .. newpass .. "\"") end
that won't work if password contains double quote inside.
Comments
Post a Comment