Toggle menu
15
236
72
27.6K
Kenshi Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:MultiReplace/doc: Difference between revisions

From Kenshi Wiki
Redirected page to Template:MultiReplace/doc
Tag: New redirect
 
Removed redirect to Template:MultiReplace/doc
Tag: Removed redirect
Line 1: Line 1:
#REDIRECT [[Template:MultiReplace/doc]]
{{Documentation subpage}}
{{lua|Module:{{#ifeq:{{NAMESPACE}}|Module|Error|MultiReplace}}}}
{{For-text
| 1 = a function to search for multiple patterns
| 2 = {{mfl|string2|matchAny}}
| 3 = a function to replace multiple parameters at once
| 4 = {{mfl|params|mapping_by_replacing}}
}}
 
[[Module:MultiReplace]] replaces matches of multiple patterns in a given string with given replacements. For each replacement instance, the pattern matching '''at the lowest position''' is chosen. If there are multiple such patterns, then the one specified earliest in the pattern list is chosen.
 
== Usage ==
{{((}}{{#ifeq:{{NAMESPACE}}|Module|&#35;invoke:MultiReplace{{!}}main|MultiReplace}}{{!}}''input''|plain=yes<small style="font-family:sans"> (optional)</small>|''pattern1''| ''replacement1''|''pattern2''|''replacement2''... {{))}}
 
If <code>plain=yes</code> is specified, then the patterns and replacements are treated as plain text, otherwise as [[mw:Extension:Scribunto/Lua reference manual#mw.ustring.gsub|Lua Unicode patterns]].
 
An equals sign in a pattern will trigger an ''Unpaired argument'' error. Use  {{tlx|{{=}}}}, which expands to an equals sign that will not be interpreted.
 
<includeonly>{{sandbox other||
[[Category:Modules]]
[[Category:String manipulation templates]]
}}</includeonly>
<noinclude>
[[Category:Module documentation pages]]
</noinclude>

Revision as of 02:16, 2 March 2025

Module:MultiReplace replaces matches of multiple patterns in a given string with given replacements. For each replacement instance, the pattern matching at the lowest position is chosen. If there are multiple such patterns, then the one specified earliest in the pattern list is chosen.

Usage

{{#invoke:MultiReplace|main|input|plain=yes (optional)|pattern1| replacement1|pattern2|replacement2... }}

If plain=yes is specified, then the patterns and replacements are treated as plain text, otherwise as Lua Unicode patterns.

An equals sign in a pattern will trigger an Unpaired argument error. Use {{}}, which expands to an equals sign that will not be interpreted.

Contents