Template:Replace/doc

From Honkai: Nexus Anima Wiki
Revision as of 03:17, 30 August 2025 by Kuhlau (talk | contribs) (Created page with "{{Documentation/Header}} {{Lua|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 [https://riptutorial.com/lua/example/20315/lua-pattern-m...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
This is the documentation page for Replace.
It contains usage information, categories, and other content not part of the original template page.
This template uses Module:Replace, a script written in Lua.

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, and here for a pattern tester.

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 removed
  • search-2 will be replaced by replace-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}} yields: hello
{{Replace|hello there|hello t|I am{space}}} yields: I am here
{{Replace|spaces are removed|{space}|}} yields: spacesareremoved
{{Replace|01010101010|0|ZERO|1|one}} yields: ZEROoneZEROoneZEROoneZEROoneZEROoneZERO
{{Replace|01010101010|0|ZERO|1|one|n = 1}} yields: ZEROoneZEROoneZEROoneZEROoneZEROoneZERO
{{Replace|01010101010|0|ZERO|1|one|n1 = 3|n2 = 1,5}} yields: ZEROoneZEROoneZEROoneZEROoneZEROoneZERO
{{Replace|this supports regular expressions too|s(.-)s|B%1E}} yields: thiB EupportB regular expreEBionE too

Template Data

Replaces all occurrences of search term in a string with the replacement term.

Template parameters

This template prefers inline formatting of parameters.

ParameterDescriptionTypeStatus
Input String1

no description

Stringrequired
Search Term 12 s1

no description

Stringrequired
Replace Term 13 r1

no description

Stringoptional
Search Term 2s2

no description

Stringoptional
Replace Term 2r2

no description

Stringoptional
Search Term 3s3

no description

Stringoptional
Replace Term 3r3

no description

Stringoptional
Search Term 4s4

no description

Stringoptional
Replace Term 4r4

no description

Stringoptional
Search Term 5s5

no description

Stringoptional
Replace Term 5r5

no description

Stringoptional