Dplreplace: Difference between revisions

From DynamicPageList3 Manual
Content added Content deleted
No edit summary
(→‎Effect: replaced: tt> → code> (2))
Line 11: Line 11:
Replaces the given ''pattern'' within the ''text'' by ''replacement''.
Replaces the given ''pattern'' within the ''text'' by ''replacement''.


''pattern'' is a regular expression as defined by php <tt>preg_replace()</tt>.
''pattern'' is a regular expression as defined by php <code>preg_replace()</code>.


''replacement'' may contain references to matching parts.
''replacement'' may contain references to matching parts.

Revision as of 06:25, 25 November 2018

Template:DPL Manual

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.

Example

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

The second example only replaces "a" by "A" if there is an "r" somewhere after the "a".