Low Replace – Documentation
Compatibility & Requirements
- Version 1.3 is compatible with EE 1.x and uses the tag
{exp:replace}. - Version 2.x is compatible with EE 2.x and uses the tag
{exp:low_replace}.
Tag pair: {exp:replace} or {exp:low_replace}
| Parameter | Description | Required |
|---|---|---|
find |
Text or pattern to replace. | Yes |
replace |
Replacement text. When not defined, an empty string is assumed. | No |
multiple |
When set to “yes”, you can use a | to define multiple values in both the find and replace parameters. |
No |
regex |
When set to “yes”, you can use a regular expression in the find parameter, and use callbacks in the replace parameter. |
No |
casesensitive |
When set to “no”, the plugin performs a case insensitive find and replace. | No |
Usage notes
ExpressionEngine strips the white space from the beginning and the end of each parameter. Because of this, if you want to replace something with a space, use the string SPACE instead. You can also use the string QUOTE for a double quote.
When using regex="yes", it is recommended that you set your Debug Preference (Admin > System Preferences > Output and Debugging Preferences) to 1, so Super Admins can make sure their regular expressions aren’t generating server errors.
Examples
Replace A with B:
{exp:low_replace find="you" replace="we"}
text you want processed
{/exp:low_replace}
Result: text we want processed
Replace A with a space:
{exp:low_replace find="o" replace="SPACE"}
text you want processed
{/exp:low_replace}
Result: text y u want pr cessed
Replace a space with nothing:
{exp:low_replace find="SPACE"}
text you want processed
{/exp:low_replace}
Result: textyouwantprocessed
Replace a new line with a space:
{exp:low_replace find="NEWLINE" replace="SPACE"}
text
you
want
processed
{/exp:low_replace}
Result: text you want processed
Replace A, B and C with D:
{exp:low_replace find="a|e|i|o|u" replace="X" multiple="yes"}
text you want processed
{/exp:low_replace}
Result: tXxt yXX wXnt prXcXssXd
Replace A, B and C with X, Y and Z:
{exp:low_replace find="text|you|want" replace="words|we|have" multiple="yes"}
text you want processed
{/exp:low_replace}
Result: words we have processed
Regular Expression find and replace:
{exp:low_replace find="\w+" replace="*" regex="yes"}
text you want processed
{/exp:low_replace}
Result: * * * *
Regular Expression find and replace with backreference:
{exp:low_replace find="<a[^>]*href=QUOTE(.+)QUOTE[^>]*>(.*)</a>" replace="$2 ($1)" regex="yes"}
<a href="https://www.foo.com/">text</a> you want <a href="https://www.bar.com/">processed</a>
{/exp:low_replace}
Result: text (https://www.foo.com/) you want processed (https://www.bar.com/)