-- Module for different search and replace operations on strings.localp={}-- Takes one string parameter, and returns the string with all characters with special meaning for Lua patterns escaped with a preceding `%`.functionp.escape_pattern(text)-- Replaces each occurrence of any of ().%+-*?[^$ with a `%` and then the character.localr=string.gsub(text,"[%(%)%.%%%+%-%*%?%[%^%$]","%%%1")returnrend-- Returns the first parameter, with all occurrences of the second parameter replaced with the third parameter.-- All special characters are ignored: {{#invoke:StringReplace|replace_all|test.a%1$foo|%1|bar}} results in `test.abarfoo`.functionp.replace_all(frame)localstr=frame.args[1]localstrToFind=frame.args[2]localstrToreplaceWith=frame.args[3]localr=string.gsub(str,p.escape_pattern(strToFind),p.escape_pattern(strToreplaceWith))returnrendp['encode wiki page name']=function(frame)localx=mw.ustring.gsub(frame.args[1]or'','[\'"&_]',{["'"]=''',['"']='"',['&']='&',['_']=' ',})returnmw.text.trim(x)endreturnp