between_regexs
Returns a string which is the subset of haystack
between the match to the regular expression start_pattern
and the match to the regular expression end_pattern
and not including either matched pattern themselves.
If no matches to start_pattern
are present in `haystack`
, returns an empty string.
If no matches to end_pattern
are present in `haystack`
, returns an empty string.
If start_pattern
or end_pattern
is empty or is an invalid regular expression, throws an exception.
Usage
{{between_regexs haystack pattern flags="t"}}
Arguments
haystack
The input string.
start_pattern
A valid regular expression.
end_pattern
A valid regular expression.
flags
- r: split text at last match to
start_pattern
and last match toend_pattern
instead of the first matches - x: expand located text: use the first match to
start_pattern
and the last match toend_pattern
- t: trim the final result prior to returning (remove all whitespace from beginning and end)
Examples
Return text between first match of start_pattern and first match of end_pattern (assuming email.body contains "This is red and that is blue and that is green.")
{{between_regexs email.body '/is/' '/is/' flags='t'}}
red and that
Return text between first match of start_pattern and last match of end_pattern (assuming email.body contains "This is red and that is blue and that is green.")
{{between_regexs email.body '/is/' '/is/' flags='tx'}}
red and that is blue and that
Return text between last match of start_pattern and last match of end_pattern (assuming email.body contains "This is red and that is blue and that is green.")
{{between_regexs email.body '/is/' '/is/' flags='tr'}}