Dplreplace

Note:

Effect
Replaces the given pattern within the text by replacement.

pattern is a regular expression as defined by php.

replacement may contain references to matching parts.

Examples
Example 1:

Replaces "ab" with "AB". This is the basic usage without using regular expressions as pattern. Matches: "ab", "ab".

Result:

Example 2:

Replaces "a" and the following characters until the next "r" with "A". This example uses a regular expression as pattern, indicated by the "/", and is using the lookahead syntax "?" to find the "r". Matches, with the group match in : "a(br)", "a(kadabr)".

Result:

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)".

Result:

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".

Result: