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

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

## <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** (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][] |

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

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

## <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 with capturing groups][]  
* <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/Select.png
[2]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/RegEx%20on%20Message%20Context/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/Example2.png
[6]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/RegEx%20on%20Message%20Context/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/
[RegEx]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/regex/
[RegEx on Message Context with capturing groups]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/regex-on-message-context-with-capturing-groups/
[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/