Skip to main content

Search and replace

Anatomy

<replace var="var" var_count="var" replacement="string" limit="(no limit)" value="string" pattern="regexp">
string
</replace>

Description: REPLACE searches a subject for occurrences of a given search value or matches to a given search pattern and replaces them with a given replacement value. The number of actual replacements is assigned to 'var_count'.

The replacement value of a regular expression may contain backreferences of the form '\n'. Every such reference will be replaced by the text captured by the n'th parenthesized pattern. '\0' always refers to the text matched by the entire search pattern.

Attributes

NameTypeDescriptionDefined By
varvarResult variable name replace
var_countvarResult variable name for number of replacements replace
replacementstringReplacement value replace
limitintLimit replace

Basic

NameTypeDescriptionDefined By
valuestringSearch value replace

Regular expression

NameTypeDescriptionDefined By
patternregexpSearch pattern replace

Results:

BindingTypePredicate
varstringN/A

Examples

Basic search and replace

<output>
<replace value="Bill Gates" replacement="William Henry Gates III">My name is Bill Gates!</replace>
</output>

<!-- My name is William Henry Gates III! -->

Regular expression search and replace

<output>
<replace pattern="/B[il]+\s*G\w+/" replacement="William Henry Gates III">My name is Bill Gates!</replace>
</output>

<!-- My name is William Henry Gates III! -->

Search and replace using backreferences

<output>
<replace pattern="/Bill ([a-z]+)/i" replacement="William Henry \1 III, call me \0">My name is Bill Gates!</replace>
</output>

<!-- My name is William Henry Gates III, call me Bill Gates! -->