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

# <i class="fal fa-function" aria-hidden="true"></i> 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.*  

## <i class="fal fa-code" aria-hidden="true"></i> 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.

## <i class="fal fa-list-ol" aria-hidden="true"></i> 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`.*  

## <i class="fal fa-circle-info" aria-hidden="true"></i> 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][].

## <i class="fal fa-hand-point-right" aria-hidden="true"></i> Next Steps

* <i class="fal fa-magnifying-glass-plus" aria-hidden="true"></i> [Add or manage Search Field][]  
* <i class="fal fa-flask" aria-hidden="true"></i> [Test Your Expression][]  
* <i class="fal fa-hard-drive" aria-hidden="true"></i> [Add or manage Log View][]  

## <i class="fal fa-link-horizontal" aria-hidden="true"></i> Related Topics

* <i class="fal fa-filter" aria-hidden="true"></i> [Extract functions][Extract Group]  
* <i class="fal fa-file-csv" aria-hidden="true"></i> [csv][]  
* <i class="fal fa-sitemap" aria-hidden="true"></i> [jsonPath][]  
* <i class="fal fa-key" aria-hidden="true"></i> [jsonPathKey][]  
* <i class="fal fa-text-slash" aria-hidden="true"></i> [regex][]  
* <i class="fal fa-database" aria-hidden="true"></i> [sqllookup][]  
* <i class="fal fa-code" aria-hidden="true"></i> [xPath][]  
* <i class="fal fa-code" aria-hidden="true"></i> [xPath2][]  
* <i class="fal fa-function" aria-hidden="true"></i> [Formula][]  
* <i class="fal fa-scroll" aria-hidden="true"></i> [Formula language rules][]  
* <i class="fal fa-puzzle-piece" aria-hidden="true"></i> [Search Field Expressions][]  
* <i class="fal fa-magnifying-glass" aria-hidden="true"></i> [RegEx with capturing groups plugin][]  

[1]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Extract/regexgroup_stringbody.png
[2]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Extract/regexgroup_stringcontext.png
[3]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Extract/Formula_RegexGroup.gif

[Add or manage Log View]:https://docs.nodinite.com/administration/log-management/log-views/features/add-or-manage-log-view/
[Add or manage Search Field]:https://docs.nodinite.com/administration/log-management/search-fields/features/add-or-manage-search-field/
[body]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/source/body/
[Choose a plugin]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/overview/#fa-signs-post-choose-a-plugin
[Context]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/source/context/
[csv]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/csv/
[Extract Group]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/overview/#extract
[Formula]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/overview/
[Formula language rules]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/overview/#fa-scroll-formula-language-rules
[jsonPath]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/jsonpath/
[jsonPathKey]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/jsonpathkey/
[Message Types]:https://docs.nodinite.com/repository-model/message-types/overview/
[Order-to-Cash demo]:https://docs.nodinite.com/repository-model/bpms/examples/order-to-cash/generate-o2c-demo-data/
[regex]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/regex/
[RegEx with capturing groups plugin]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/regex-with-capturing-groups/
[Search Field Expressions]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/overview/
[sqllookup]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/sqllookup/
[Test Your Expression]:https://docs.nodinite.com/administration/log-management/search-fields/features/add-or-manage-search-field/#test-your-expression
[xPath]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/xpath/
[xPath2]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/xpath2/