Template:Str mulrepc
.
Returns string0 with all (or the specified) occurrences of string1 replaced with string2
Usage
{{Str mulrepc |1= |2= |3= }}
{{Str mulrepc|<string0>|<string1>|<string2>|<count>|<plainflag>}}
Template parameters
Parameter | Description | Default | Status | |
---|---|---|---|---|
1 | source text string | empty | required | |
2 | pattern string | empty | required | |
3 | replacement string | nil | optional | |
4 | number (when not all patterns should be replaced) | all | optional | |
5 | flag whether pattern is plain value: set 'false' when regexp | true | optional |
Additional information
The template is intended to be used in the following namespaces: no namespace specified
The template is intended to be used by the following user groups: no user group specified
Limitations
Because the three strings need to be single parameters, they must not contain any pipe |
character.
Anyway, pipe characters can be substituted by e.g. {{!}}
(or {{!!}}
, {{!(}}
, {{!-}}
, {{)!}}
).
REGEXP pattern characters ( ) . % - * ? [ ^ $ ]
can be used either like other characters when the plainflag contains the default value true
,
or the can be used for REGEXP functions with the pattern (string1
) when plainflag is changed to false
.
The strings are not trimmed before they are used, the specification of string1
and string2
has to be specified carefully
An unspecified count
defaults for 'all occurrences'.
"Expensive" template.
Patterns
About all pattern possibilities, see the detailed Lua documentation.
Examples
e.g. a parameter string representing several parameters: replace all "/" by "|"
{{Str mulrepc|abc/def/ghi|/|{{!}}}}
→ abc|def|ghi
e.g. replace "A" by "?", not more than two times
{{Str mulrepc|aAaAaAaA|A|?|2}}
→ a?a?aAaA
e.g. replace "/" by "|"
{{Str mulrepc|47° 50′ 07.15″ N, 7° 43′ 23.16″ E/dim:160|/|{{!}}}}
→ 47° 50′ 07.15″ N, 7° 43′ 23.16″ E|dim:160
e.g. a regular expression: change double angle brackets "</>" around any text to double curly brackets "{/}"
{{Str mulrepc|<<legend>>|<<([^>] )>>|{{%1}}|1|false}}
→ Template:legend
See also
Trimming templates:
- {{Trunc}} – To trim down to a specified number of characters.
- {{Trim}} — To trim any leading or trailing whitespace.
- {{Str left}} – To trim down to a specified number of characters, or duplicate the string to a specified number.
- {{Str right}}
- {{Strip}} – To strip (remove) a given number of characters from the beginning/end of the string
Analyzing templates:
- {{Str endswith}} – To check if a string ends with a given string.
- {{Str find}} – Returns the numerical location of a given string in a string, up to 50 characters.
- {{Str len}} – Returns a string's length. Can count up to 500 characters.
String length comparison templates:
- {{Str ≤ len}} – To check if a string is "shorter or equally long" or "longer" than a given length.
Technical stuff:
- mw:Help:Magic words – About
{{padleft:|}}
. - mw:Help:Extension:ParserFunctions – About
{{#titleparts:|}}, {{#expr:|}}, {{#ifeq:|}},
etc. - Module:String - Script with native string parsing