RegEx on Message Context with Capturing Groups Plugin
Section titled “ 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

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.
When to use it
Section titled “ 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 |
Expression syntax
Section titled “ Expression syntax”Select RegEx on Message Context with capturing groups in the Type list. The plugin shows these fields:

The RegEx on Message Context with capturing groups plugin in the Type list.
| Field | What goes in it |
|---|---|
| Expression | The regular expression, with at least one capturing group ( ). 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\sor[ ], 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 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 removes aren't kept, so don't base a Search Field on them.

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 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.
Examples
Section titled “ Examples”Example 1: Extract the 4th field from a pipe-delimited order record
Section titled “Example 1: Extract the 4th field from a pipe-delimited order record”| Key | Value |
|---|---|
OrderRecord |
ORD|101|ExampleCompany1|456|Company Name ACME |Dieselgate valley 1|123 45|Flameburg| |
Expression
Section titled “Expression”-
Expression:
^(?:(.*?)\|){4} -
RegEx groups:
1 -
Global: unchecked
-
Multi line: unchecked
-
Context key:
OrderRecord
Result
Section titled “Result”456The group repeats four times and keeps the last value: ORD, 101, ExampleCompany1, then 456.

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
Section titled “Example 2: Extract the order number from the file name that BizTalk received”| Key | Value |
|---|---|
http://schemas.microsoft.com/BizTalk/2003/file-properties#ReceivedFileName |
C:\Integration\In\Orders\PO_4711.xml |
Expression
Section titled “Expression”-
Expression:
PO_(\d+)\.xml -
RegEx groups:
1 -
Global: unchecked
-
Multi line: unchecked
-
Context key:
http://schemas.microsoft.com/BizTalk/2003/file-properties#ReceivedFileName
Result
Section titled “Result”4711The same pattern in RegEx on Message Context returns the whole match, PO_4711.xml.

RegEx groups 1 returns only the digits inside the parentheses.