Template:Str mulrepc

Template documentationview · edit · history · purge ]
This documentation is transcluded from Template:Str mulrepc/doc.


.

Returns string0 with all (or the specified) occurrences of string1 replaced with string2

Usage

{{Str mulrepc |1= |2= |3= }}

Or use the shorthand
{{mrep|… parameters as described …}}

{{Str mulrepc|<string0>|<string1>|<string2>|<count>|<plainflag>}}

Template parameters

ParameterDescriptionDefaultStatus
1source text stringemptyrequired
2pattern stringemptyrequired
3replacement stringniloptional
4number (when not all patterns should be replaced)alloptional
5flag whether pattern is plain value: set 'false' when regexptrueoptional

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.

Sandboxes and test cases:

Technical stuff: