Help:Regular expressions
| Driver's Manual | ||||||||||||
| Page | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| New • Search • Info • Move • Delete | ||||||||||||
| Editing | ||||||||||||
| ||||||||||||
| Account | ||||||||||||
| Account • Preferences | ||||||||||||
| Directory... |
Regular expressions (shorthand regex) are patterns designed to match all or parts of a text string, often with the goal of then transforming the subject according to custom, complex logic. This is possible using metacharacters, which assign special meanings to specific keys, as pertaining to positional variables, option sets, or even groups to capture – that is, keeping "memory" of certain parts, to incorporate back into the replacement.
Usage
Parser functions
Courtesy of RegexFunctions, the {{#rmatch:}}, {{#rsplit:}}, and {{#rreplace:}} parser functions implement the most essential regex operations at the page source level. These contribute remarkable utility with other powerful extensions, particularly Cargo and DynamicPageList; One potential application might resolve parse order complexities around extension tags, to do with the infamous "QINU" issue.[1]
Software tools
Regex enables the irreplaceable AutoWikiBrowser, an interface for performing automated, wiki-wide find-and-replace operations. Administrators have access to the on-site Special:ReplaceText tool, a less robust but still highly convenient alternative.
Note also that JavaScript supports regex; Lua uses its own system, though they are quite similar.
Resources
| # | Key | Name | Meaning |
|---|---|---|---|
| 1. | \ |
Backslash | Escape a metacharacter to its literal meaning, -or- signify a token. |
| 2. | ^ |
Caret | Anchor start of string. |
| 3. | | |
Pipe | Logical OR: Designate alternation between options. |
| 4. | . |
Period | Wildcard: Match any character except newline. |
| 5. | $ |
Dollar sign | Anchor end of string. |
| 6. | ? |
Question mark | Quantifier: Zero or one i.e. "Optional";[3] See also greediness. |
| 7. | * |
Asterisk | Quantifier: Zero or more |
| 8. | + |
Plus sign | Quantifier: One or more |
| 9. | ( |
Opening Parenthesis | Isolate a capture group. Reference contents in output via positional index $1, $2, etc.
|
| 10. | ) |
Closing Parenthesis | |
| 11. | [ |
Opening Square bracket | Define a character class: option list or range of character selection. ] doesn't normally need escape as meaning depends on the former.
|
| 12. | { |
Opening curly bracket | Quantifier: Enclosed n (any integer). Optionally add , with or without upper limit p (p > n). Ending note above applies also to }.
|
Tutorials
- Regular expression on Wikipedia
- AutoWikiBrowser pattern guide
- Regular expressions - JavaScript flavor
- Regular expression HOWTO - Python flavor
- Regular-Expressions.info
- www.regextutorial.org
Important to familiarize is Multiline Mode, in which the anchor keys ^ and $ match beginning and end of the entire string, not one single line as standard.
Convenient examples
| Pattern | Application | Tests | |
|---|---|---|---|
\[\[([^|\]\n]+)(?:\|([^\]\n]+))?\]\]
|
Extract the target page $1 and if applicable, display text $2 of an internal link. Replace each [/] with {/} to match an equivalent template call.
|
Input:[[Page Link|Page Text]]
|
Capture return: $1 = Page Link$2 = Page Text
|
<([a-z]+)>(.*?)<\/\1>
|
Get the name $1 and contents $2 of an HTML tag set.
|
Input:<span>Example text</span>
|
Capture return: $1 = span$2 = Example text
|
^(.*?)\:(.*?)
|
Capture prefix $1 and page name $2 from a full page title.
|
Input:Help:Regular expressions
|
Capture return: $1 = Help$2 = Regular expressions
|
(\x7F)*\'\"\`UNIQ(.*?)QINU\`\"\'(\x7F)*
|
Eliminate failed strip marker substitutions from the output, keeping their inner content $1.
|
Input:'"`UNIQ--ref-00000023-QINU`"'
|
Capture return: $1 = --ref-00000023-
|
References
- ↑ Template:DBref - Mini proof-of-concept pitching substitution and subsequent restoration of extension tag names while working with Cargo. Essentially, store user-defined keys as wrapper representations, then manipulate the query result via RegexFunctions to restore intended meaning and parse at precisely the correct transclusion stage.
- ↑ "Regex Metacharacters". www.RegexTutorial.org. Retrieved March 12, 2026.
- ↑ "The Question Mark Makes the Preceding Token Optional". Regular-Expressions.info, www.Regular-Expressions.info. Retrieved March 12, 2026.

