INPUT:
1
2
3
2
3
local str = 'a b c'
str = replace(str, ' b ', ' d ')
print(str)
1
a d c
Thanks!
local str = 'a b c'
str = replace(str, ' b ', ' d ')
print(str)
a d c
function replace(str, pattern, rep)
return string.gsub(str, pattern, rep)
end
do
local function regexEscape(str)
return str:gsub("[%(%)%.%%%+%-%*%?%[%^%$%]]", "%%%1")
end
string.replace = function (str, this, that)
return str:gsub(regexEscape(this), that:gsub("%%", "%%%%")) -- only % needs to be escaped for 'that'
end
end