Skip to main content

before_string

Returns a string which is the subset of haystack before needle and not including `needle` itself. If `needle` is not present in haystack, returns an empty string. If needle is empty, throws an exception.

Usage​

{{before_string haystack needle flags="irnt"}}

Arguments​

haystack
The input string

needle
The boundary string

flags

  • i: treat delimiter as not case-sensitive (default is case-sensitive)
  • r: split text at last instance of needle instead of the first
  • n: return only the text on the same line as the needle (from the last newline before needle)
  • t: trim the final result prior to returning (remove all whitespace from beginning and end)

Examples​

Return text before first instance of needle, assuming email.body contains "This is red and that is blue and that is green."

{{before_string email.body 'is' flags='t'}}
This

Return the text before the last instance of needle, assuming email.body contains "This is red and that is blue and that is green."

{{before_string email.body 'is' flags='tr'}}
This is red and that is blue and that