Runtime verified Test scripts included

Applies a regular expression (Java regex syntax) to a string and returns the matched text or one capture group. Returns an empty string when nothing matches.

Syntax

{{regExMatch subject pattern group [...options]}}

Returns string.

Parameters

Name Type Required Description
subject string Yes String to search.
pattern string Yes The regular expression to apply.
group string Yes Name or number of the capture group to return; “0” is the whole match.
options any No, repeatable Named boolean flags: explicitCapture, ignoreCase, ignorePatternWhitespace, multiline.

Example

Tested in a Marketing Cloud Next email on 2026-11-22:

  • {{regExMatch "abc123" "[0-9]+" "0"}} renders 123, as documented.
  • {{regExMatch "save10" "^[A-Z0-9]{5,7}$" "0" ignoreCase=true}} renders save10, as documented.
  • {{regExMatch "abc" "[0-9]+" "0"}} renders an empty string, as documented.
Show Next test script
<!-- Marketing Cloud Next test script for the regExMatch helper. Paste it into the HTML component of a
     Next email and open the preview. Each line prints the result Next gave when the call
     was rendered on its own (expect) next to the result of this run (got).
     Assembled from single-call test emails (dates on the page); it has not been
     run as one email. Calls that make Next fail are listed separately. -->
<p>c1 expect=[123] got=[{{regExMatch "abc123" "[0-9]+" "0"}}]</p>
<p>c2 expect=[save10] got=[{{regExMatch "save10" "^[A-Z0-9]{5,7}$" "0" ignoreCase=true}}]</p>
<p>c3 expect=[] got=[{{regExMatch "abc" "[0-9]+" "0"}}]</p>

Marketing Cloud Next

Works as documented

Every tested call rendered the documented result. Tested 2026-11-22 by rendering in a Marketing Cloud Next email.

See also