Add string.escapepattern function

This commit is contained in:
Aleksi Juvani 2017-04-10 13:52:36 +03:00
parent ad6e49c136
commit 87e001d4e9

View File

@ -91,3 +91,13 @@
return self .. "s"
end
end
---
-- Returns the string escaped for Lua patterns.
---
function string.escapepattern(s)
return s:gsub("[%(%)%.%%%+%-%*%?%[%]%^%$]", "%%%0")
end