---
title: RegEx on Message Context Plugin – Extract Whole Matches from a Context Property
description: Use the Nodinite RegEx on Message Context Search Field Expression plugin to run a regular expression on the value of one named context property and return every whole match, for example the file name from a full file path.
---

# :fa-magnifying-glass: RegEx on Message Context Search Field Expression Plugin

The **RegEx on Message Context** plugin reads the value of one named context property of a [Log Event][] and returns every **whole match** of a regular expression in that value. Use it when the value you want is part of a context property, such as the file name at the end of a full file path.

* ✅ Reads one of the context properties, chosen by its key  
* ✅ Returns the whole match; the message body is never read  

## :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** (this page) |
| One context value (you know the key) | Only the part inside a capturing group | [RegEx on Message Context with capturing groups][] |
| 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** in the **Type** list. The plugin shows two fields:

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

| Field | What goes in it |
| --- | --- |
| **RegEx** | The [regular expression][RegEx] to run on the context value. The help text under the field ends with *"The pattern ignores case and white space: write a space as `\s` or `[ ]` and # as `\#` (an unescaped # starts a comment)."* |
| **Context key** | The key of the context property to read. The key is case-sensitive: `filename` doesn't find `FileName`. |

* The result is the whole match. To return only a capturing group, use [RegEx on Message Context 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 match is dropped. A pattern may run for 30 seconds per event at most.
* 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 and the help texts under RegEx 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.*  

![RegEx on Message Context with capturing groups returns ORD-10009 from the FileName context value, animated walkthrough (7.12)][4]  
*Animated walkthrough: the sibling plugin [RegEx on Message Context with capturing groups][] reads the `FileName` context value of a logged order confirmation and returns group 1, `ORD-10009`. With this plugin, the same pattern would return the whole match `ORD-10009-`.*  

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 file name from a file path

#### Input

| Key | Value |
| --- | --- |
| `FileName` | `\\nodinitesrv01\ftp\public\INT001\Order\OrderFile_123.xml` |

#### Expression

* **RegEx**:

  ```text
  ([^\\]+$)
  ```

* **Context key**: `FileName`

#### Result

```text
OrderFile_123.xml
```

`[^\\]+$` matches the characters after the last backslash, up to the end of the value.

![Test Expression for RegEx on Message Context returning OrderFile_123.xml from the FileName context key (7.12)][2]  
*Test Expression: the file name extracted from the `FileName` context value on the Message Context tab.*  

### Example 2: Extract 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

* **RegEx**:

  ```text
  ([^\\]+$)
  ```

* **Context key**: `http://schemas.microsoft.com/BizTalk/2003/file-properties#ReceivedFileName`

#### Result

```text
PO_4711.xml
```

To get only the order number `4711`, use `PO_(\d+)\.xml` with [RegEx on Message Context with capturing groups][].

![RegEx on Message Context test: a pattern for the text after the last backslash, on the ReceivedFileName key, returns PO_4711.xml (7.12)][5]  
*The pattern keeps everything after the last backslash: the file name.*  

## :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 with capturing groups][]  
* :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/Select.png
[2]:{ndm}/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/RegEx%20on%20Message%20Context/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/Example2.png
[6]:{ndm}/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/RegEx%20on%20Message%20Context/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
[RegEx]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/RegEx.md
[RegEx on Message Context with capturing groups]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/RegEx%20on%20Message%20Context%20with%20capturing%20groups.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