r:replace
<r:replace />
This tag uses regular expressions to replace the content inside the tag with whatever characters you specify.
Attribute Options:
-
match
- The regular expression pattern to use to match what characters to replace. String. -
with
- The characters to replace what was matched in thematch
attribute. String.
Examples:
<r:replace match="WordPress" with="CleanSlate">
WordPress is the best CMS.
</r:replace>
<!-- Output: "CleanSlate is the best CMS." -->
<!-- RegEx matches any digit -->
<r:replace match="\d" with="A">123</r:replace>
<!-- Output: "AAA" -->
<!-- Regex to grab individual strings, sans commas and spaces -->
<!-- Regex from: https://stackoverflow.com/a/5001626 -->
<r:replace match="[^,\s][^\,]*[^,\s]*" with="Renamed tag">
tag_1, tag 2, label-3, example
</r:replace>
<!-- Output: "Renamed tag, Renamed tag, Renamed tag, Renamed tag" -->
{{ "Hello World" | replace: "Hello", "Hi" }}
Replaces every occurrence of the first argument in a string with the second argument.
View the official Liquid documentation for the replace filter.
Examples
{{ "Wordpress is the best CMS" | replace: "Wordpress", "CleanSlate" }}
<!-- Output: "CleanSlate is the best CMS." -->
<!-- Input: page.name = "Wordpress is the best CMS" -->
{{ page.name | replace: "Wordpress", "CleanSlate" }}
<!-- Output: "CleanSlate is the best CMS." -->
{{ "Morgantown is located in Morgantown, WV." | replace_first: "Morgantown", "WVU" }}
<!-- Output: "WVU is located in Morgantown, WV." -->
Note: Liquid does not support Regular Expressions (RegEx) due to security reasons. It does have a wide variety of Filters that can likely suit your needs.
Last updated on March 16, 2021.
We welcome all questions, feedback and bug reports. If you're having an issue, we usually need the following information:
- A brief description of the issue
- A link to the page where you saw the issue
- Screenshots that illustrate the problem - How do I take a screenshot?
Kindly email CleanSlate@mail.wvu.edu for help or use the form on the request help page.