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.

ParameterTypeDescription
sourceStringStringRequired. The string to search.
regExPatternStringRequired. The regular expression to apply to sourceString.
returnValueStringRequired. The name or ordinal of the matching group to return. Use "0" to return the full match.
explicitCaptureBooleanIndicates whether the expression captures only explicitly named groups. Specify as a named parameter.
ignoreCaseBooleanIndicates whether the regular expression uses case-insensitive matching. Specify as a named parameter.
ignorePatternWhitespaceBooleanIndicates whether to exclude unescaped white space from the pattern. Specify as a named parameter.
multilineBooleanIndicates 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: