Formula - regexgroup
Section titled “ Formula - regexgroup”The regexGroup Formula function returns the value of a capturing group of a regular expression, instead of the whole match that regex returns.

Animated walkthrough: on the Order Entry XML of order ORD-10011 in the Order-to-Cash demo, the expression is limited to its Message Type and tested. regex returns each whole <SKU>…</SKU> element, tags included; regexGroup with group '1' returns only the three SKU values.
Syntax
Section titled “ Syntax”regexGroup('expression', 'groups', content)Parameters
Section titled “Parameters”| Parameter | Required | Description |
|---|---|---|
'expression' |
Yes | A .NET regular expression with at least one capturing group ( ), in single quotes. Backslashes are written once ('\d+'). |
'groups' |
Yes | The number of the capturing group to return, such as '1' for the first group. Quoted '1' and unquoted 1 both work. |
content |
Yes | The text to search: body, context, or the result of another function (see Formula language rules). |
Returns
Section titled “Returns”The value of the selected group for every match, one value each; duplicates are collapsed. When a group repeats inside one match (for example (…){4}), the value from its last repetition is returned. When nothing matches, nothing is returned.
Examples
Section titled “ Examples”Example 1: Read the order IDs from the body
Section titled “Example 1: Read the order IDs from the body”ID=123,CUSTOMER=1ID=456,CUSTOMER=2Formula
Section titled “Formula”regexGroup('ID=(\d+)', '1', body)Result
Section titled “Result”123456
Group 1 captures only the digits after ID=, so the ID= prefix is not part of the result.
Example 2: Read the fourth field of a pipe-delimited context value
Section titled “Example 2: Read the fourth field of a pipe-delimited context value”The Message Context key OrderRecord holds a pipe-delimited order record:
| Key | Value |
|---|---|
| OrderRecord | ORD|101|ExampleCompany1|456|Company Name ACME |Dieselgate valley 1|123 45|Flameburg| |
Formula
Section titled “Formula”regexGroup('^(?:(.*?)\|){4}', 1, context('OrderRecord'))Result
Section titled “Result”456
(?:(.*?)\|){4} repeats four times from the start of the value; group 1 keeps the last repetition, the fourth field (counted from 1), 456.
\|matches a literal pipe; an unescaped|means "or" in a regular expression.- To return the whole match instead of a group, use regex.
- For one pattern on the body, the RegEx with capturing groups plugin returns groups without a formula, and accepts several group numbers or names. See Choose a plugin.