This one’s on the house
Compatibility: | EE1, EE2, EE3, EE4 |
---|---|
Latest release: | 3.0.0 (released 2015-10-25) |
Licensing: | CC Attribution-Share Alike 3.0 |
Compatibility
The download package contains both the EE2 and EE3+ versions. The EE1 compatible version is no longer under development, but is still available on Github.
Installation
ExpressionEngine 3+
- Download and unzip Low Replace
- Copy the
ee3/low_replace
folder to your/system/user/addons/
directory - In your Control Panel, go to the Add-on Manager and install Low Replace.
- All set!
ExpressionEngine 2
- Download and unzip Low Replace
- Copy the
ee2/low_replace
folder to your/system/expressionengine/third_party/
directory - All set!
Template tags
Parameter | Description |
---|---|
case |
When set to yes , the plugin performs a case sensitive find and replace. |
find |
Text or pattern to replace. Required. |
flags |
Additional pattern modifiers, use in combination with regex="yes" . Use the case parameter instead of the i flag. |
multiple |
When set to yes , you can use a | to define multiple values in both the find and replace parameters. |
regex |
When set to yes , you can use a regular expression in the find parameter, and use callbacks in the replace parameter.When set to raw , you can use a full regular expression pattern, including delimiters and flags. The case and flags parameters are ignored. |
replace |
Replacement text. Defaults to an empty string. |
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, PIPE
for a | and NEWLINE
to match new lines.
When using regex="yes"
, it is recommended that you set your Debug Preference 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="http://www.foo.com/">text</a> you want <a href="http://www.bar.com/">processed</a>
{/exp:low_replace}
Result: text (http://www.foo.com/) you want processed (http://www.bar.com/)