Dplreplace: Difference between revisions
Content added Content deleted
imported>FrozenPlum mNo edit summary |
imported>FrozenPlum m (Fix these to have working examples and add a note to come back to this) |
||
Line 2: | Line 2: | ||
==Syntax== |
==Syntax== |
||
<pre |
<pre> |
||
{{#dplreplace:text|pattern|replacement}} |
|||
</pre> |
|||
==Effect== |
==Effect== |
||
Line 13: | Line 13: | ||
''replacement'' may contain references to matching parts. |
''replacement'' may contain references to matching parts. |
||
== |
==Examples== |
||
<pre> |
|||
<nowiki> {{#dplreplace:abrakadabra|ab|AB}} </nowiki> returns: {{#dplreplace:abrakadabra|ab|AB}} |
|||
{{#dplreplace:abrakadabra|ab|AB}} |
|||
</pre> |
|||
Replaces "ab" with "AB". |
|||
<nowiki> {{#dplreplace:abrakadabra|/a(.*?)r/|A\1_r_}} </nowiki> returns: {{#dplreplace:abrakadabra|/a(.*?)r/|A\1_r_}} |
|||
'''Result:'''<br> |
|||
⚫ | |||
{{#dplreplace:abrakadabra|ab|AB}} |
|||
<pre> |
|||
{{#dplreplace:abrakadabra|/a(.*?)r/|A\1_r_}} |
|||
</pre> |
|||
⚫ | |||
{{note|This explanation is incomplete, it needs to be expanded to better explain what is taking place in the result.}} |
|||
'''Result:'''<br> |
|||
{{#dplreplace:abrakadabra|/a(.*?)r/|A\1_r_}} |
|||
[[Category:Other Modules]] |
[[Category:Other Modules]] |
Revision as of 08:27, 5 April 2022
|
Manual | dplreplace |
Syntax
{{#dplreplace:text|pattern|replacement}}
Effect
Replaces the given pattern within the text by replacement.
pattern is a regular expression as defined by php preg_replace()
.
replacement may contain references to matching parts.
Examples
{{#dplreplace:abrakadabra|ab|AB}}
Replaces "ab" with "AB".
Result:
{{#dplreplace:abrakadabra|ab|AB}}
{{#dplreplace:abrakadabra|/a(.*?)r/|A\1_r_}}
Replaces "a" by "A" if there is an "r" somewhere after the "a".
Result:
{{#dplreplace:abrakadabra|/a(.*?)r/|A\1_r_}}