From the RuneScape Wiki, the wiki for all things RuneScape
Jump to navigation Jump to search
Template documentation
This documentation is transcluded from Template:Replace/doc. [edit] [history] [purge]
Template:Replace invokes function main in Module:Replace using Lua.

Acts as a regex-supporting version of {{#replace:}}.

Some functions of standard regex (Perl compatible) are not supported.

  • No flags (g, i, m)
  • No alteration (|); see below
  • No generalized quantifier ({m,n})
  • No word boundaries (\b)

Lua's pattern matching is used for this template; however, the following replacements are made to give some functionality to standard regex:

  • *?-
  • \%
  • $1%1 (supported for all numbers 1–9)

Any whitespace in the output will be automatically trimmed and condensed. Any HTML entities (such as ' from {{subst:PAGENAME}}) will be automatically converted to their actual character.


If detected, the module can emulate very simple alteration patterns within groups, with the following limitations:

  • No supported for nested grouping (e.g. (foo|bar(and|or)baz)
    • Escaped parentheses should work properly inside grouping (e.g. (foo|bar\(or\)baz))
  • $ will cause unwanted behaviour inside any groups, even if that group doesn't use alteration
    • This only applies to patterns where at least 1 group has an alteration. If all groups are single captures, this behaviour won't occur.
  • The pipe character breaks wikitext. Use {{!}} or ¦ inside patterns
MediaWiki docs

For full information on the difference between Lua's pattern matching and regex, see Lua reference manual § Patterns.


This template should always be substituted.

{{subst:replace|text to perform on|search pattern|replacement}}
Expected: capture
{{subst:replace|Abyssal whip detail.png|detail\.png}}Abyssal whip
Expected: Abyssal whip
Expected: ^ab^^c^^d^e
Expected: $a###-$b###-c$d###-e
Expected: !ab!cde