Text replacement helpers process are used to extract or convert text. For example, helpers can be used to extract a piece of information from an email so that the information can be used somewhere.
There are four categories of text replacement helpers:
- string helpers extract text before, after, or between specific strings
- line helpers extract one or more lines of text
- regex helpers extract text before, after, or between regular expressions, or extract strings that match a regular expression
- date helpers convert date formats, add or subtract time, and convert between timezones
The structure of text replacement helpers
Text replacement helpers are identifiers followed by zero or more parameters each separated by a space. Each parameter is itself an expression.
{{helper_name argument1 argument2 argument3 argument4=""}}
|-----------| |---------| |------------|
| | |
The name of the A positional A named
helper argument argument
For example, this expression uses the before_string helper to extract the portion of john@domain.com before the first @, and would render john:
{{before_string 'john@domain.com' '@'}}
And since each parameter is itself an expression, we can change 'john@domain.com' to email.from.address like this:
{{before_string email.from.address '@'}}
We can even change 'john@domain.com' to another expression, nested in parentheses like this:
{{before_string (between_strings email.body "Email Address:" "\n") '@'}}
Denoting strings with quote marks
Notice that the first example has single quotes around 'email@domain.com', and the second example has no quotes around email.from.address.
The quotes in the first example cause the before_string helper to use the literal text email@domain.com.
The lack of quotes in the second example cause before_string to first render email.from.address as an expression before then using the results of that expression. In this way, the second example would first render email.from.address to the email sender's address, and then would extract the part of that email before the @ sign.
We recognize single quotes and double quotes as valid text delimiters in expressions. The following expressions would render the exact same text:
{{before_string 'john@domain.com' '@'}}
{{before_string "john@domain.com" "@"}}
{{before_string "john@domain.com" '@'}}
{{before_string 'john@domain.com' "@"}}