---
title: RegEx on Message Context with Capturing Groups Plugin – Extract Part of a Context Property
description: Use the Nodinite RegEx on Message Context with capturing groups Search Field Expression plugin to run a regular expression on one named context property and return only the capturing group you choose, for example a field from a delimited value.
---

# <i class="fal fa-magnifying-glass" aria-hidden="true"></i> RegEx on Message Context with Capturing Groups Plugin

The **RegEx on Message Context with capturing groups** plugin reads the value of one named context property of a [Log Event][] and returns only the text inside the **capturing group** you choose. Use it to pick a value out of a context property, such as one field of a delimited record or the order number inside a file name.

* ✅ Reads one of the context properties, chosen by its key; the message body is never read  
* ✅ Returns one or several capturing groups, with **Global** and **Multi line** options  

![RegEx on Message Context with capturing groups returns ORD-10009 from the FileName context value, animated walkthrough (7.12)][4]  
*Animated walkthrough: the pattern `^(ORD-\d+)-` with group `1` and **Context key** `FileName` reads the context value `ORD-10009-order-confirmation-delivered-to-customer.csv` of a logged Order-to-Cash order confirmation and returns `ORD-10009`.*  

## <i class="fal fa-scale-balanced" aria-hidden="true"></i> When to use it

Four RegEx plugins cover the combinations of *where the text is* and *what part of the match you want*. For every plugin, see [Choose a plugin][].

| Your data | You want | Use |
| --- | --- | --- |
| Message body | The whole match | [RegEx][] |
| Message body | Only the part inside a capturing group `( )` | [RegEx with capturing groups][] |
| One context value (you know the key) | The whole match | [RegEx on Message Context][] |
| One context value (you know the key) | Only the part inside a capturing group | **RegEx on Message Context with capturing groups** (this page) |
| One context value (you know the key) | The value as it is, no pattern | [Message Context Key][] |
| XML stored in a context value | An XPath result | [XPath on Message Context][] |

## <i class="fal fa-code" aria-hidden="true"></i> Expression syntax

Select **RegEx on Message Context with capturing groups** in the **Type** list. The plugin shows these fields:

![Type list open with the Expression Types, among them RegEx on Message Context with capturing groups (7.12)][1]  
*The RegEx on Message Context with capturing groups plugin in the Type list.*  

| Field | What goes in it |
| --- | --- |
| **Expression** | The [regular expression][RegEx], with at least one [capturing group][RegEx with capturing groups] `( )`. It runs on the context value; the help text under the field says *"RegEx expression used to extract data from the value of the context key"* and ends with *"The pattern ignores case and white space: write a space as `\s` or `[ ]` and # as `\#` (an unescaped # starts a comment)."* |
| **RegEx groups** | The [RegEx][] group or groups to return: a single number (`1`), a list (`1,3,4,5,6`), a range (`1,3-6`), or group names (`value1,value2`, with no space after the comma). Group `0` is the whole match, and named groups are numbered after the unnamed ones. Left empty, the plugin returns the whole match. The help text under the field: *"The groups to return, comma-separated: group numbers (1,3,4 or a range 1,3-6; 0 is the whole match, named groups are numbered after the unnamed ones) and/or group names (value1,value2). Leave empty to return the whole match."* |
| **Global** | Checked: return every match in the value. Unchecked: stop after the first match. |
| **Multi line** | Checked: `^` and `$` match the start and end of each line in the value. |
| **Context key** | The key of the context property to read. The key is case-sensitive: `filename` doesn't find `FileName`. |

* Groups are numbered from 1 in the order their opening parentheses appear; `(?: )` is non-capturing. A repeated group keeps the value of its last repetition, as explained on [RegEx with capturing groups][].
* Matching ignores case. Spaces in the pattern are ignored, and `#` starts a comment: write a literal space as `\s` or `[ ]`, and a literal `#` as `\#`.
* Each value is trimmed of leading and trailing white space, and an empty group is dropped. A pattern may run for 30 seconds per event at most.
* The **Global** checkbox above belongs to the plugin. The dialog has a second **Global** under **Apply to**, which applies the expression to all [Message Types][] (see [Add or manage Search Field][]).
* Write the key exactly as it's logged. [BizTalk][BizTalk Logging] context properties are logged as *namespace#property*, for example `http://schemas.microsoft.com/BizTalk/2003/file-properties#ReceivedFileName`.
* Context properties and the reserved keys are described in [Context Options][]. Properties that the [ContextPropertiesFilters][] [System Parameter][System Parameters] removes aren't kept, so don't base a [Search Field][Search Fields] on them.

![Expressions tab with Type RegEx on Message Context with capturing groups and the help texts under Expression, RegEx groups, and Context key (7.12)][6]  
*The plugin's fields with their help texts.*  

* To test, add the key and its value on the **Message Context** tab of Test Expression. When the key is missing or nothing matches, the test reports *Processed with warning: The Expression yields no result*:

![Test Expression result: Processed with warning, The Expression yields no result (7.12)][3]  
*Test result when the key is missing or the pattern matches nothing in its value.*  

Configure and test the expression as described in [Add or manage Search Field][] and [Test Your Expression][].

## <i class="fal fa-list-ol" aria-hidden="true"></i> Examples

### Example 1: Extract the 4th field from a pipe-delimited order record

#### Input

| Key | Value |
| --- | --- |
| `OrderRecord` | `ORD\|101\|ExampleCompany1\|456\|Company Name ACME \|Dieselgate valley 1\|123 45\|Flameburg\|` |

#### Expression

* **Expression**:

  ```text
  ^(?:(.*?)\|){4}
  ```

* **RegEx groups**: `1`
* **Global**: unchecked
* **Multi line**: unchecked
* **Context key**: `OrderRecord`

#### Result

```text
456
```

The group repeats four times and keeps the last value: `ORD`, `101`, `ExampleCompany1`, then `456`.

![Test Expression for RegEx on Message Context with capturing groups returning 456 from the OrderRecord context key (7.12)][2]  
*Test Expression: the 4th field of the `OrderRecord` context value on the Message Context tab.*  

### Example 2: Extract the order number from the file name that BizTalk received

#### Input

| Key | Value |
| --- | --- |
| `http://schemas.microsoft.com/BizTalk/2003/file-properties#ReceivedFileName` | `C:\Integration\In\Orders\PO_4711.xml` |

#### Expression

* **Expression**:

  ```text
  PO_(\d+)\.xml
  ```

* **RegEx groups**: `1`
* **Global**: unchecked
* **Multi line**: unchecked
* **Context key**: `http://schemas.microsoft.com/BizTalk/2003/file-properties#ReceivedFileName`

#### Result

```text
4711
```

The same pattern in [RegEx on Message Context][] returns the whole match, `PO_4711.xml`.

![RegEx on Message Context with capturing groups test: a pattern that captures the digits of the file name in group 1 returns 4711 (7.12)][5]  
*RegEx groups `1` returns only the digits inside the parentheses.*  

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

* <i class="fal fa-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-signs-post" aria-hidden="true"></i> [Choose a plugin][]  

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

* <i class="fal fa-magnifying-glass" aria-hidden="true"></i> [RegEx on Message Context][]  
* <i class="fal fa-key" aria-hidden="true"></i> [Message Context Key][]  
* <i class="fal fa-magnifying-glass" aria-hidden="true"></i> [XPath on Message Context][]  
* <i class="fal fa-magnifying-glass" aria-hidden="true"></i> [RegEx][]  
* <i class="fal fa-magnifying-glass" aria-hidden="true"></i> [RegEx with capturing groups][]  
* <i class="fal fa-function" aria-hidden="true"></i> [Formula][]  
* <i class="fal fa-filter" aria-hidden="true"></i> [ContextPropertiesFilters][]  
* <i class="fal fa-magnifying-glass-plus" aria-hidden="true"></i> [Search Field Expressions][]  
* <i class="fal fa-magnifying-glass-plus" aria-hidden="true"></i> [Search Fields][]  

[1]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/RegEx%20on%20Message%20Context%20with%20capturing%20groups/Select.png
[2]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/RegEx%20on%20Message%20Context%20with%20capturing%20groups/Example1.png
[3]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/NoResult.png
[4]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Expression_RegExContext.gif
[5]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/RegEx%20on%20Message%20Context%20with%20capturing%20groups/Example2.png
[6]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/RegEx%20on%20Message%20Context%20with%20capturing%20groups/Help.png

[Add or manage Search Field]:https://docs.nodinite.com/administration/log-management/search-fields/features/add-or-manage-search-field/
[BizTalk Logging]:https://docs.nodinite.com/logging-and-monitoring/microsoft-biztalk-server-logging/overview/
[Choose a plugin]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/overview/#fa-signs-post-choose-a-plugin
[Context Options]:https://docs.nodinite.com/core-services/log-event/features/context-options/
[ContextPropertiesFilters]:https://docs.nodinite.com/administration/settings/system-parameters/contextpropertiesfilters/
[Formula]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/overview/
[Log Event]:https://docs.nodinite.com/core-services/log-event/overview/
[Message Context Key]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/message-context-key/
[Message Types]:https://docs.nodinite.com/repository-model/message-types/overview/
[RegEx]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/regex/
[RegEx on Message Context]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/regex-on-message-context/
[RegEx with capturing groups]: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/
[Search Fields]:https://docs.nodinite.com/administration/log-management/search-fields/features/what-is-a-search-field/
[System Parameters]:https://docs.nodinite.com/administration/settings/system-parameters/overview/
[Test Your Expression]:https://docs.nodinite.com/administration/log-management/search-fields/features/add-or-manage-search-field/#test-your-expression
[XPath on Message Context]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/xpath-on-message-context/