lua-string match the magic characters

2019-01-18

to escapse the magic character , we have to use ‘%’ to turn off pattern match when call string.find or gsub functions

1
2
3
4
5
6
function test_string()
local name = "res${CALLERID(name)}"
local s1,s2 = string.gsub(name,"$%{CALLERID%(name%)%}", "lilizhou")
print(s1)
print(s2)
end

in the exampe, we try to replace the whole string ‘${CALLERID(name)}’ with a new string.