Handlebars Helper Function: regExMatch
Searches a string for a pattern by using a regular expression and returns the result.
This helper is available in the Winter ’27 release of Marketing Cloud Next.
| Parameter | Type | Description |
|---|---|---|
sourceString | String | Required. The string to search. |
regExPattern | String | Required. The regular expression to apply to sourceString. |
returnValue | String | Required. The name or ordinal of the matching group to return. Use "0" to return the full match. |
explicitCapture | Boolean | Indicates whether the expression captures only explicitly named groups. Specify as a named parameter. |
ignoreCase | Boolean | Indicates whether the regular expression uses case-insensitive matching. Specify as a named parameter. |
ignorePatternWhitespace | Boolean | Indicates whether to exclude unescaped white space from the pattern. Specify as a named parameter. |
multiline | Boolean | Indicates whether to use multiline mode, where ^ and $ indicate the beginning and end of each line instead of the beginning and end of sourceString. Specify as a named parameter. |
The helper supports the same regular expression patterns and options as the java.util.regex package. See Java Platform API Specification: Class Pattern.
The function returns text from the source string that matches the specified pattern. If the pattern doesn’t match any content from the source string, the function returns an empty string.
This example validates a subscriber-supplied coupon code by checking whether it contains five to seven alphanumeric characters, and returns the matched code.
The pattern matches the entire string.
Because the value of the ignoreCase option is true, the pattern matches the entire couponCode string, even though the string uses only lowercase letters and the pattern specifies only uppercase letters. The helper returns: