Skip to main content

after_regex

Returns a string which is the subset of haystack after the match to the regular expression pattern and not including the matched pattern itself.

If no matches to pattern are present in `haystack`, returns an empty string.

If pattern is empty or is an invalid regular expression, throws an exception.

Usage​

{{after_regex haystack pattern flags="rnt"}}

Arguments​

haystack
The input string.

pattern
A valid regular expression.

flags

  • r: return text after the last match instead of the first match
  • n: return only the text on the same line as the match (up to the first newline after the match)
  • t: trim the final result prior to returning (remove all whitespace from beginning and end)

Examples​

Return text after first match of pattern (assuming email.body contains "This is red and that is blue and that is green.")

{{after_regex email.body '/that/' flags='t'}}
is blue and that is green.

Return text after last match of pattern (assuming email.body contains "This is red and that is blue and that is green.")

{{after_regex email.body '/that/' flags='tr'}}
is green.

Return an empty string if no match of pattern (assuming email.body contains "This is red and that is blue and that is green.")

{{after_regex email.body '/pizza/' flags='t'}}