Took a little longer than expected, but this works for me:Tested but unfortunately same result.
Code:
function Initialize() tab = {some = 'Here is (something'}endfunction Esc(str) --local esc = string.format('%q', str) local esc = str:gsub('([%^%$%(%)%%%.%[%]%*%+%-%?])', '%%%1') return escendfunction Output(key) SKIN:Bang('!SetOption', 'Text', 'Text', tab[key]) SKIN:Bang('!Update')endfunction ShowText() print(Esc(tab.some)) SKIN:Bang('!SetOption', 'TextMeasure', 'String', tab.some) SKIN:Bang('!Update') local txt = SKIN:GetMeasure('TextMeasure'):GetStringValue() for line in txt:gmatch('[^\r\n]+') do for key, val in pairs(tab) do print(key, val, line) if line:match(Esc(val)) then print('matched'); Output(key) else print('not matched') end end end return 0end
What I initially recommended works though, and as I believe it should happen, only the literal pattern (i.e. val or tab[some]) needs escaping, nothing else. There is a catch though - I tried escaping stuff like \n or \s after in the main string, and except literally using \\n and \\s there or declaring it as tab = {some = [[Here is (something]]}, I got mixed results: it either didn't work (tried local esc = str:gsub('([%^%$%(%)%%%.%[%]%*%+%-%?])', '%%%1'):gsub('\\', '\\\\')), or it partially work and it kept the \ but not the n afterwards. You can use " aka double quotes in the string without having to escape them, but not ' aka apostrophes / single quotes, though you can invert that if you want.
Statistics: Posted by Yincognito — 54 minutes ago