Template:Replace
Template documentation
|
---|
Note: portions of the template sample may not be visible without values provided. |
View or edit this documentation. (About template documentation) |
Editors can experiment in this template's sandbox and test case pages. |
File:Wiki.png |
This template uses Lua: Module:Replace |
This template replaces occurrences of any number of search terms in a string. By default, all occurrences of the search terms will be replaced with the desired terms, but particular occurrences of a search term (e.g., the first occurrence) can be specified.
This template uses Lua's Regular Expression (RegEx) version, which can also be used in this template's parameters. See here for an explanation on how to use this RegEx variant.
Syntax
- Base function
{{Replace|<input string>|<search term>|<replacement term>}}
- Multiple replacement
{{Replace|<input string>|<search-1>|<replace-1>|<search-2>|<replace-2>|<...>|<search-X>|<replace-X>}}
- Each pair of unnamed parameters after the input string will be treated as a pair of search and replacement terms
- Direct removals
{{Replace|<input string>|s1 = <search-1>|s2 = <search-2>|s3 = <search-3>}}
- When no pairing replacement term is given, the searched term will instead be removed from the input string.
- Mixed usage
{{Replace|<input string>|s1 = <search-1>|s2 = <search-2>|r2 = <replace-2>|s3 = <search-3>|r4 = <replace-4>}}
search-1
will be removedsearch-2
will be replaced byreplace-2
search-3
will be removed- As no
search-4
was given,replace-4
is ignored
- Key terms
The following terms will be replaced by the specified characters when used in the search or replace parameters
{space}
by{newline}
by<br>
Examples
{{Replace|<hi>|<i>|<ello>}}
{{Replace|<hello there>|<hello t>|<I am{space}>}}
{{Replace|<spaces are removed>|<{space}>|<...>}}
{{Replace|<01010101010>|<0>|<ZERO>|<1>|<one>}}
{{Replace|<01010101010>|<0>|<ZERO>|<1>|<one>}}
{{Replace|<01010101010>|<0>|<ZERO>|<1>|<one>}}
{{Replace|<this supports regular expressions too>|<s(.-)s>|<B%1E>}}
Template Data
Replaces all occurrences of search term in a string with the replacement term.
Parameter | Description | Type | Status | |
---|---|---|---|---|
Input String | 1 | no description | String | required |
Search Term 1 | 2 s1 | no description | String | required |
Replace Term 1 | 3 r1 | no description | String | optional |
Search Term 2 | s2 | no description | String | optional |
Replace Term 2 | r2 | no description | String | optional |
Search Term 3 | s3 | no description | String | optional |
Replace Term 3 | r3 | no description | String | optional |
Search Term 4 | s4 | no description | String | optional |
Replace Term 4 | r4 | no description | String | optional |
Search Term 5 | s5 | no description | String | optional |
Replace Term 5 | r5 | no description | String | optional |