---
title: "Formula - regexGroup: Extract Regular Expression Capturing Groups"
description: The regexGroup Formula function returns the value of a capturing group of a regular expression instead of the whole match. Includes syntax, parameters, and body and context examples.
---

# :fa-function: 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.

![Return only the SKU of every order line with regexGroup instead of regex, animated walkthrough (7.12)][3]  
*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][Message Types] and tested. `regex` returns each whole `<SKU>…</SKU>` element, tags included; `regexGroup` with group `'1'` returns only the three SKU values.*  

## :fa-code: Syntax

```text
regexGroup('expression', 'groups', content)
```

### 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][Context], or the result of another function (see [Formula language rules][]).|  

### 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.

## :fa-list-ol: Examples

### Example 1: Read the order IDs from the body

#### Input

```text
ID=123,CUSTOMER=1
ID=456,CUSTOMER=2
```

#### Formula

```text
regexGroup('ID=(\d+)', '1', body)
```

#### Result

```text
123
456
```

![Formula regexGroup expression returning two ID values from a text message body in the Test Expression tab (7.12)][1]  
*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

#### Input

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

```text
regexGroup('^(?:(.*?)\|){4}', 1, context('OrderRecord'))
```

#### Result

```text
456
```

![Formula regexGroup expression returning the fourth pipe-delimited field from the OrderRecord context property in the Message Context tab (7.12)][2]  
*`(?:(.*?)\|){4}` repeats four times from the start of the value; group 1 keeps the last repetition, the fourth field (counted from 1), `456`.*  

## :fa-circle-info: Notes

* `\|` 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][].

## :fa-hand-point-right: Next Steps

* :fa-magnifying-glass-plus: [Add or manage Search Field][]  
* :fa-flask: [Test Your Expression][]  
* :fa-hard-drive: [Add or manage Log View][]  

## :fa-link-horizontal: Related Topics

* :fa-filter: [Extract functions][Extract Group]  
* :fa-file-csv: [csv][]  
* :fa-sitemap: [jsonPath][]  
* :fa-key: [jsonPathKey][]  
* :fa-text-slash: [regex][]  
* :fa-database: [sqllookup][]  
* :fa-code: [xPath][]  
* :fa-code: [xPath2][]  
* :fa-function: [Formula][]  
* :fa-scroll: [Formula language rules][]  
* :fa-puzzle-piece: [Search Field Expressions][]  
* :fa-magnifying-glass: [RegEx with capturing groups plugin][]  

[1]:{ndm}/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Extract/regexgroup_stringbody.png
[2]:{ndm}/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Extract/regexgroup_stringcontext.png
[3]:{ndm}/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Extract/Formula_RegexGroup.gif

[Add or manage Log View]:{ndr}/Administration/1.%20Log%20Management/1.%20Log%20Views/Features/Add%20or%20Manage%20Log%20View.md
[Add or manage Search Field]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Add%20or%20manage%20Search%20Field.md
[body]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Source/body.md
[Choose a plugin]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Overview.md#fa-signs-post-choose-a-plugin
[Context]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Source/context.md
[csv]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Extract/csv.md
[Extract Group]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Overview.md#extract
[Formula]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Overview.md
[Formula language rules]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Overview.md#fa-scroll-formula-language-rules
[jsonPath]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Extract/jsonPath.md
[jsonPathKey]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Extract/JsonPathKey.md
[Message Types]:{ndr}/Repository%20Model/Message%20Types/Overview.md
[Order-to-Cash demo]:{ndr}/Repository%20Model/BPMs/Examples/Order-to-Cash/Generate-O2C-Demo-Data.md
[regex]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Extract/regex.md
[RegEx with capturing groups plugin]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/RegEx%20with%20capturing%20groups.md
[Search Field Expressions]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Overview.md
[sqllookup]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Extract/sqllookup.md
[Test Your Expression]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Add%20or%20manage%20Search%20Field.md#test-your-expression
[xPath]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Extract/xPath.md
[xPath2]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Extract/xPath2.md