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="irt"}}

Arguments

haystack
The input string

haystack
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
  • 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