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

# :fa-magnifying-glass: 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`.*  

## :fa-scale-balanced: 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][] |

## :fa-code: 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][].

## :fa-list-ol: 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.*  

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

* :fa-plus: [Add or manage Search Field][]  
* :fa-flask: [Test Your Expression][]  
* :fa-signs-post: [Choose a plugin][]  

## :fa-link-horizontal: Related Topics

* :fa-magnifying-glass: [RegEx on Message Context][]  
* :fa-key: [Message Context Key][]  
* :fa-magnifying-glass: [XPath on Message Context][]  
* :fa-magnifying-glass: [RegEx][]  
* :fa-magnifying-glass: [RegEx with capturing groups][]  
* :fa-function: [Formula][]  
* :fa-filter: [ContextPropertiesFilters][]  
* :fa-magnifying-glass-plus: [Search Field Expressions][]  
* :fa-magnifying-glass-plus: [Search Fields][]  

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

[Add or manage Search Field]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Add%20or%20manage%20Search%20Field.md
[BizTalk Logging]:{ndr}/Logging%20and%20Monitoring/Microsoft%20BizTalk%20Server%20-%20Logging/Overview.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 Options]:{ndr}/Core%20Services/Log%20Event/Features/Context%20Options.md
[ContextPropertiesFilters]:{ndr}/Administration/5.%20Settings/5.%20System%20Parameters/ContextPropertiesFilters.md
[Formula]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Overview.md
[Log Event]:{ndr}/Core%20Services/Log%20Event/Overview.md
[Message Context Key]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Message%20Context%20Key.md
[Message Types]:{ndr}/Repository%20Model/Message%20Types/Overview.md
[RegEx]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/RegEx.md
[RegEx on Message Context]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/RegEx%20on%20Message%20Context.md
[RegEx with capturing groups]:{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
[Search Fields]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/What%20is%20a%20Search%20Field.md
[System Parameters]:{ndr}/Administration/5.%20Settings/5.%20System%20Parameters/Overview.md
[Test Your Expression]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Add%20or%20manage%20Search%20Field.md#test-your-expression
[XPath on Message Context]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/XPath%20on%20Message%20Context.md