Dplreplace

From DynamicPageList3 Manual
Revision as of 09:25, 5 April 2022 by miraheze:dpl3>Soukupmi (→‎Examples: breaking example 2 into 2 separate ones)
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

Example 1:

{{#dplreplace:abrakadabra|ab|AB}}

Replaces "ab" with "AB".

Result:
{{#dplreplace:abrakadabra|ab|AB}}


Example 2:

{{#dplreplace:abrakadabra|/a(.*?)r/|A\1r}}

Replaces "a" by "A" if there is an "r" somewhere after the "a". The "\1r" part is needed to put back the original text into the replaced string.
{{#dplreplace:abrakadabra|/a(.*?)r/|A}} (without the "\1r") would otherwise lead to "{{#dplreplace:abrakadabra|/a(.*?)r/|A}}".

Result:
{{#dplreplace:abrakadabra|/a(.*?)r/|A\1r}}


Example 3:

{{#dplreplace:abrakadabra|/a(.*?)r/|A\1_r_}}

Replaces "a" by "A" if there is an "r" somewhere after the "a" and also replaces the "r" at the end of the found group(s) by "_r_".

Result:
{{#dplreplace:abrakadabra|/a(.*?)r/|A\1_r_}}