Formula - regex
Section titled “ Formula - regex”The regex Formula function returns every whole match of a regular expression in text content.

Animated walkthrough: on the Order Entry XML of the Order-to-Cash demo, regex returns the ERP reference ERP-2025-10005. Nested in replaceregex, the ERP-2025- prefix is removed and 10005 remains.
Syntax
Section titled “ Syntax”regex('expression', content)Parameters
Section titled “Parameters”| Parameter | Required | Description |
|---|---|---|
'expression' |
Yes | A .NET regular expression in single quotes. Backslashes are written once ('\d+'); a literal ' is written ''. |
content |
Yes | The text to search: body, context, or the result of another function (see Formula language rules). |
Returns
Section titled “Returns”Every whole match, one value each; duplicates are collapsed. Capturing groups in the pattern don't change the result: regex always returns the whole match. To return a group instead, use regexGroup. When nothing matches, nothing is returned.
regex(...) is also the argument form of context and contextKey, where it selects context keys by pattern.
Examples
Section titled “ Examples”Example 1: Find a number in the body
Section titled “Example 1: Find a number in the body”This is number 5Formula
Section titled “Formula”regex('\d+', body)Result
Section titled “Result”5
\d+ matches the run of digits; the backslash is written once.
Example 2: Match a value in a context property
Section titled “Example 2: Match a value in a context property”| Key | Value |
|---|---|
| id | GMT |
Formula
Section titled “Formula”regex('GMT|UTC', context('id'))Result
Section titled “Result”GMT
The alternation GMT|UTC matches GMT in the value of id.
Example 3: Match across several context properties
Section titled “Example 3: Match across several context properties”| Key | Value |
|---|---|
| id | GMT UTC |
| id2 | GMT CTO |
Formula
Section titled “Formula”regex('UTC|CTO', context(regex('id.*')))Result
Section titled “Result”UTCCTO
context(regex('id.*')) returns both values; regex searches each and returns one match from each.
Example 4: Pick the invoice number from a text message
Section titled “Example 4: Pick the invoice number from a text message”Invoice INV-2024-0042 for order PO-1001 is due 2024-11-30Formula
Section titled “Formula”regex('INV-\d{4}-\d{4}', body)Result
Section titled “Result”INV-2024-0042
Only the INV- pattern matches; the order number PO-1001 and the due date are left out.
- Patterns are not anchored; add
^and$when the whole value must match. - Formula regexes ignore unescaped whitespace and treat
#as the start of a comment: write a literal space as\sor[ ]and a literal#as\#or[#]. Matching is case-insensitive. See the Formula language rules. - For large text bodies, keep the pattern specific so the engine doesn't scan more than needed.
- For one pattern on the body, the RegEx plugin does the same without a formula; for context values, use the RegEx on Message Context plugin. See Choose a plugin.