Home
Random
Log in
Settings
About the Petit Planet Wiki
Search
Editing
Template
:
Replace/doc
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{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-matching here] for an explanation on how to use this RegEx variant. ==Syntax== ;Base function {{T|Replace|v1=input string|v2=search term|v3=replacement term}} ;Multiple replacement {{T|Replace|v1=input string|v2=search-1|v3=replace-1|v4=search-2|v5=replace-2|v6=...|v7=search-X|v8=replace-X}} * Each pair of unnamed parameters after the input string will be treated as a pair of search and replacement terms ;Direct removals {{T|Replace|v1=input string|v2=s1=search-1|v3=s2=search-2|v4=s3=search-3}} * When no pairing replacement term is given, the searched term will instead be removed from the input string. ;Mixed usage {{T|Replace|v1=input string|v2=s1=search-1|v3=s2=search-2|v4=r2=replace-2|v5=s3=search-3|v6=r4=replace-4}} * {{F|v=1|search-1}} will be removed * {{F|v=1|search-2}} will be replaced by {{F|v=1|replace-2}} * {{F|v=1|search-3}} will be removed * As no {{F|v=1|search-4}} was given, {{F|v=1|replace-4}} is ignored ;Key terms The following terms will be replaced by the specified characters when used in the search or replace parameters * {{F|{space} }} by {{F| }} * {{F|{newline} }} by {{F|<br>|nw=1}} ==Examples== {{T|Replace|hi|i|ello|_Y_=1}}<br> {{T|Replace|hello there|hello t|I am{space}|_Y_=1}}<br> {{T|Replace|spaces are removed|{space}||_Y_=1}}<br> {{T|Replace|01010101010|0|ZERO|1|one|_Y_=1}}<br> {{T|Replace|01010101010|0|ZERO|1|one|n=1|_Y_=1}}<br> {{T|Replace|01010101010|0|ZERO|1|one|n1=3|n2=1,5|_Y_=1}}<br> {{T|Replace|this supports regular expressions too|s(.-)s|B%1E|_Y_=1}}<br> ==Template Data== <templatedata> { "params": { "1": { "label": "Input String", "type": "string", "required": true }, "2": { "aliases": [ "s1" ], "label": "Search Term 1", "type": "string", "required": true }, "3": { "label": "Replace Term 1", "type": "string", "aliases": [ "r1" ] }, "s2": { "label": "Search Term 2", "type": "string" }, "r2": { "label": "Replace Term 2", "type": "string" }, "s3": { "label": "Search Term 3", "type": "string" }, "r3": { "label": "Replace Term 3", "type": "string" }, "s4": { "label": "Search Term 4", "type": "string" }, "r4": { "label": "Replace Term 4", "type": "string" }, "s5": { "label": "Search Term 5", "type": "string" }, "r5": { "label": "Replace Term 5", "type": "string" } }, "description": "Replaces all occurrences of search term in a string with the replacement term.", "format": "inline" } </templatedata>
Summary:
Please note that all contributions to The Petit Planet Wiki are considered to be released under the Creative Commons Attribution-ShareAlike (see
Petit Planet Wiki:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Preview page with this template
Below are commonly used wikitext from
MediaWiki:Edittools
. Click on any to insert them in the edit box.
File Pages
==Summary==
==Licensing==
{{Fairuse}}
{{File|}}
Dynamic Page List
¦
²
«
»
²{¦}²
«»
«/»
«!----»
Array in DPL
¹
^2{
}^2
^2{¹}^2
Parser Functions
{{#if:||}}
{{#if:<condition>|<result if true>|<result if false>}}
{{#ifeq:|||}}
{{#ifeq:<text1>|<text2>|<result if text1=text2>|<result if text1≠text2>}}
{{#expr:}}
{{#expr:<mathematical expression>}}
{{#switch:||#default=}}
{{#switch:<text1>|<text2>=<result if text1=text2>|<text3>=<result if text1=text3>|#default=<result if no valid match>}}
{{#replace:||}}
{{#replace:<text1>|<plain text to find in text1>|<plain text to insert in place of the text found>}}
{{#titleparts:}}
{{#replace:<page name>}}
{{#tag:|}}
{{#tag:<name of html tag>|<content inside html tag>}}
Markup
{{}}
|
[]
[[]]
[[Category:]]
#REDIRECT [[]] [[Category:Redirect Pages]]
<code></code>
<includeonly></includeonly>
<noinclude></noinclude>
<nowiki></nowiki>
<!---->
<br>
§
Notices
{{Stub|}}
{{Stub Dialogue}}
{{Upcoming}}
{{Under Construction}}
{{Placeholder|}}
Magic Words
{{!}}
{{formatnum:}}
{{lc:}}
{{uc:}}
{{PAGENAME}}
{{FULLPAGENAME}}
{{ROOTPAGENAME}}
{{BASEPAGENAME}}
{{SUBPAGENAME}}
{{DISPLAYTITLE:|noreplace}}
__TOC__
__NOTOC__
__EXPECTUNUSEDCATEGORY__
__HIDDENCAT__
HTML Entities
—
,
­
Pages included on this page:
Template:Array
(
edit
)
Template:Documentation/Header
(
edit
)
Template:Documentation/styles.css
(
edit
)
Template:F
(
edit
)
Template:Lua
(
edit
)
Template:MessageBox
(
edit
)
Template:Namespace
(
edit
)
Template:Replace
(
edit
)
Template:T
(
edit
)
Module:Arguments
(
edit
)
Module:Arguments/i18n
(
edit
)
Module:Array
(
edit
)
Module:Common/i18n
(
edit
)
Module:Config
(
edit
)
Module:Documentation
(
edit
)
Module:Documentation/config
(
edit
)
Module:Documentation/i18n
(
edit
)
Module:Entrypoint
(
edit
)
Module:Exists
(
edit
)
Module:Fallbacklist
(
edit
)
Module:Feature
(
edit
)
Module:Formatting
(
edit
)
Module:I18n
(
edit
)
Module:Languages
(
edit
)
Module:Mbox
(
edit
)
Module:Mbox/i18n
(
edit
)
Module:Namespace detect
(
edit
)
Module:Namespace detect/config
(
edit
)
Module:Namespace detect/data
(
edit
)
Module:Replace
(
edit
)
Module:TableTools
(
edit
)
Module:Yesno
(
edit
)