Module:Pattern utilities: Difference between revisions
Jump to navigation
Jump to search
Bob>Djpwikiadmin Created page with "local export = {} -- A helper function to escape magic characters in a string when interpolating a string into a Lua pattern. -- Magic characters: ^$()%.[]*+-? function expor..." |
m 1 revision imported |
(No difference)
| |
Latest revision as of 08:10, 15 April 2026
Documentation for this module may be created at Module:Pattern utilities/doc
local export = {}
-- A helper function to escape magic characters in a string when interpolating a string into a Lua pattern.
-- Magic characters: ^$()%.[]*+-?
function export.pattern_escape(text)
if type(text) == "table" then
text = text.args[1]
end
text = mw.ustring.gsub(text, "([%^$()%%.%[%]*+%-?])", "%%%1")
return text
end
-- A helper function to escape magic characters in a string when interpolating a string into a Lua pattern replacement
-- string (the right side of a gsub() pattern substitution call).
-- Magic characters: %
function export.replacement_escape(text)
if type(text) == "table" then
text = text.args[1]
end
text = mw.ustring.gsub(text, "%%", "%%%%")
return text
end
return export