This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing.
localp={}localgetArgs=require('Module:Arguments').getArgs--args: 1 - ustring pattern, 2 - value if present, 3 - value if absent, -- page - page to test if not this pagefunctionp._main(args)ifnotargs["page"]thenargs.page=mw.title.getCurrentTitle().fullTextendlocalpage=mw.title.new(args.page)ifnotpagethen--bad titlereturnargs["3"]or""endlocalcontent=page:getContent()ifnotcontentthen--page does not existreturnargs["3"]or""endifmw.ustring.match(content,args["1"]or"")thenifargs["sub"]then--return value should have capture groups substed inlocalpattern=args["1"]or""ifmw.ustring.sub(pattern,1,1)~="^"then--pattern does not force it to be at start of pagepattern="^.-"..patternendifmw.ustring.sub(pattern,-1)~="$"then--pattern does not force it to be at end of pagepattern=pattern..".*$"end--pattern will now match entire content, so running gsub will--return the string that has been passed in parameter 2 with things--like %1 substituted, NOTE: %0 does not work in thislocalout=mw.ustring.gsub(content,pattern,args["2"]or"")returnoutelsereturnargs["2"]or""endelsereturnargs["3"]or""endendfunctionp.main(frame)localargs=getArgs(frame)returnp._main(args)endreturnp