Help:Dplreplace
From Dragon Mania Legends (DML) Wiki
|
Manual | dplreplace |
This DPL3 module replaces a given pattern
withing given text
by the given replacement
.
Syntax
{{#dplreplace:text|pattern|replacement}}
, where:
text
is whatever text is to be searched within.pattern
is a regular expression as defined by phppreg_replace()
.replacement
may contain references to matching parts.
Note: If you are not familiar with regular expressions or do not know the specifics of Perl regexp used in PHP, it may be helpful to see:
- The PHP manual and W3Schools for more information.
- RegExr for testing regular expressions.
Examples
Example 1:
This replaces "ab" with "AB". This is the basic usage without using regular expressions as pattern.
{{#dplreplace:abrakadabra|ab|AB}}
Example 2:
This replaces "a" and its following characters until the next "r", with "A". This example uses a regular expression as pattern, indicated by the "/" characters, and is using the lookahead syntax ?
to find the "r".
Matches, with the group match in (): "a(br)", "a(kadabr)".
{{#dplreplace:abrakadabra|/a(.*?r)/|A}}
Example 3:
Replaces "a" with "A" if there is an "r" somewhere after the "a". The \1
references the group found between the "a" and "r" and puts it back into the replaced string.
Matches, with the group match in (): "a(br)", "a(kadabr)".
{{#dplreplace:abrakadabra|/a(.*?r)/|A\1}}
Example 4:
Replaces "a" with "A" if there is an "r" somewhere after the "a", and also replaces the "r" at the end of/outside the found group(s) with "_r_".
Matches, with the group match in (): "a(b)r", "a(kadab)r".
{{#dplreplace:abrakadabra|/a(.*?)r/|A\1_r_}}