---
title: XPath with RegEx Search Field Expression Plugin for XML in Nodinite
description: "Extract part of an XML value with the Nodinite XPath with RegEx Search Field Expression plugin: XPath selects the element, a regular expression extracts the part you need. Covers the XPath, Treat sub XML as a string, RegEx, RegEx groups, and Global fields."
---

# <i class="fal fa-magnifying-glass" aria-hidden="true"></i> XPath with RegEx Search Field Expression Plugin

The **XPath with RegEx** plugin extracts values from XML in the message body in two steps: an [XPath][] 1.0 expression selects an element, and a regular expression extracts the part of its value you need. Use it when the value you want is only part of an element, such as a file name at the end of a path.

* ✅ Cut a file name, an ID, or a code out of a longer XML value  
* ✅ **Treat sub XML as a string** lets the [RegEx][] read the markup of a sub-tree, including element names  
* ✅ **RegEx groups** returns only the capturing groups you choose  

![XPath with RegEx expression tested on a logged order file message, animated walkthrough (7.12)][5]  
*Animated walkthrough: pick the **XPath with RegEx** type, select the file name element with **XPath**, cut the name from the path with **RegEx to style value**, and test it on the logged message; the **Result** shows OrderFile_123.xml.*  

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

| Your data | Use |
| --- | --- |
| Plain XML in the message body; you want element or attribute values as they are | [XPath][] |
| Only part of an XML value (a file name in a path, an ID in a formatted string), or tag names inside an XML sub-tree | **XPath with RegEx** (this page) |
| XML stored as escaped text inside an element of another XML message | [XPath on wrapped XPath][XPath on Wrapped XPath] |
| XML stored in a context property instead of the body | [XPath on Message Context][] |
| Full XPath over the whole document (look-back steps, predicates on child elements), or XPath combined with other functions (decode Base64 first, concatenate, compare) | [Formula][] with [xPath2][Formula xPath2] |

For non-XML bodies, use [RegEx][] or [RegEx with capturing groups][] on the whole message; for the other plugins, see [Choose a plugin][].

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

<div class="mermaid">
graph LR
    A["fa:fa-file-code XML message body"] --> B["XPath<br/>selects the element"]
    B --> C["RegEx to style value<br/>extracts from its value"]
    C --> D["fa:fa-magnifying-glass-plus Unique values"]
    style A fill:#2678BD,color:#fff
    style B fill:#E47528,color:#fff
    style C fill:#9E59BB,color:#fff
    style D fill:#93d16d,color:#000
</div>

*XPath runs first (orange) on the body (blue); the RegEx (purple) runs on each selected value; the matches become the [Search Field][Search Fields] values (green).*  

The plugin shows these fields:

| Field | What goes in it |
| --- | --- |
| **XPath** | An [XPath 1.0][XPath] expression that selects the element, written from the root without a leading `/` (`Orders/Header/FileName`). Element names match without namespace prefixes; the supported syntax is listed in [Allowed XPath expressions][]. |
| **Treat sub XML as a string** | Off: the [RegEx][] runs on the element's text value. On: the RegEx runs on everything from the selected XPath as a string, markup included, so it can match tags and attributes. |
| **RegEx to style value** | The [regular expression][RegEx] that extracts data from the [XPath][] value. Despite the field label, it extracts; it doesn't format the value. In 7.12, its help text ends with *"The pattern ignores case and white space: write a space as `\s` or `[ ]` and # as `\#` (an unescaped # starts a comment)."* |
| **RegEx groups** | Which [capturing groups][RegEx with capturing groups] of the [RegEx][] to return: group numbers (`1,3` or a range `1,3-6`; `0` is the whole match, and named groups are numbered after the unnamed ones) or group names (`value1,value2`), comma-separated. Left empty, it returns the whole match. In 7.12, the help text under the field reads: *"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** | On: keep matching after the first match (*Don't return after first match*). Off: return only the first match. |

Duplicates are collapsed into unique values ([How expressions run][]). Pick the plugin in the **Type** list when you [add or manage a Search Field][Add or manage Search Field], and check the result in the **Test Expression** tab ([Test Your Expression][]). The **Test Expression** tab has its own **Treat sub XML as a string** and **Global** checkboxes: tick them there, then press **Test**.

![Test Expression tab with Type XPath with RegEx and its own Treat sub XML as a string and Global checkboxes ticked (7.12)][6]  
*Both checkboxes ticked on the **Test Expression** tab.*  

![Type list filtered on XPath with, the XPath with RegEx plugin selected (7.12)][1]  
*Selecting **XPath with RegEx** in the **Type** list.*  

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

### Example 1: Get the file name from a full file path

The header holds the full path of the received file; the Search Field should hold only the file name.

#### Input

```xml
<ns0:Orders xmlns:ns0="Common.Schemas/Nodinite/1.0">
    <Header>
        <FileName>\\nodinitesrv01\ftp\public\INT001\Order\OrderFile_123.xml</FileName>
    </Header>
    <Order>
        <Id>101</Id>
        <Amount>1000</Amount>
        <City>Gothenburg</City>
    </Order>
</ns0:Orders>
```

#### Expression

| Field | Value |
| --- | --- |
| XPath | `Orders/Header/FileName` |
| Treat sub XML as a string | Off |
| RegEx to style value | `([^\\]+$)` |

#### Result

```text
OrderFile_123.xml
```

XPath returns `\\nodinitesrv01\ftp\public\INT001\Order\OrderFile_123.xml`; the RegEx matches the characters after the last backslash. The whole match and group 1 are the same here.

![Test Expression tab with XPath with RegEx returning OrderFile_123.xml (7.12)][2]  
*XPath `Orders/Header/FileName` plus RegEx `([^\\]+$)` returns one unique match, `OrderFile_123.xml`. The form and the result fill the screen; the body is the Input above.*  

### Example 2: List the element names inside a sub-tree

#### Input

```xml
<Envelope>
    <Any>
        <Nodes>
            <node1 id="1">
                <node2/>
            </node1>
        </Nodes>
    </Any>
</Envelope>
```

#### Expression

| Field | Value |
| --- | --- |
| XPath | `Envelope/Any/Nodes` |
| Treat sub XML as a string | On |
| RegEx to style value | `<([a-z0-9]{0,})` |
| RegEx groups | `1` |
| Global | On |

#### Result

```text
node1
node2
```

`Nodes` contains only elements, so its text value is empty: without **Treat sub XML as a string** the RegEx has nothing to match. With it on, the RegEx reads the markup. Group 1 returns the name after each `<`, and **Global** keeps matching after the first one. The closing tag `</node1>` gives an empty group, which doesn't appear in the result.

![Test Expression tab with XPath with RegEx returning node1 and node2 (7.12)][4]  
***Treat sub XML as a string**, **RegEx groups** 1, and **Global** turned on: 2 unique matches, `node1` and `node2`.*  

## <i class="fal fa-triangle-exclamation" aria-hidden="true"></i> Limitations

* The XPath step uses the same forward-only reader as the [XPath][] plugin, so only the syntax in [Allowed XPath expressions][] works.
* The RegEx runs on the value the XPath selects, never on the rest of the message.

An unsupported expression, or one that matches nothing, gives this result in the test:

![Test result: Processed with warning, The Expression yields no result (7.12)][3]  
*No match: the test reports **Processed with warning: The Expression yields no result** instead of values.*  

## <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-list-check" aria-hidden="true"></i> [Allowed XPath expressions][]  
* <i class="fal fa-table-list" aria-hidden="true"></i> [Add or manage Log View][]  

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

* <i class="fal fa-magnifying-glass" aria-hidden="true"></i> [XPath][]  
* <i class="fal fa-magnifying-glass" aria-hidden="true"></i> [XPath on wrapped XPath][XPath on Wrapped XPath]  
* <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 xPath2][]  
* <i class="fal fa-signs-post" aria-hidden="true"></i> [Choose a plugin][]  
* <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][]  
* <i class="fal fa-file" aria-hidden="true"></i> [Message Types][]  
* <i class="fal fa-table-list" aria-hidden="true"></i> [Log Views][]  

[1]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/XPath%20with%20RegEx/XpathWithRegExSelection.png
[2]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/XPath%20with%20RegEx/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/XPath%20with%20RegEx/Example2.png
[5]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Expression_XPathRegEx.gif
[6]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/XPath%20with%20RegEx/TestTabTicked.png

[Add or manage Log View]:https://docs.nodinite.com/administration/log-management/log-views/features/add-or-manage-log-view/
[Add or manage Search Field]:https://docs.nodinite.com/administration/log-management/search-fields/features/add-or-manage-search-field/
[Allowed XPath expressions]:https://docs.nodinite.com/administration/log-management/search-fields/troubleshooting/allowed-xpath-expressions/
[Choose a plugin]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/overview/#fa-signs-post-choose-a-plugin
[Formula]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/overview/
[Formula xPath2]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/xpath2/
[How expressions run]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/overview/#fa-gears-how-expressions-run
[Log Views]:https://docs.nodinite.com/administration/log-management/log-views/features/what-is-a-log-view/
[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 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/
[Test Your Expression]:https://docs.nodinite.com/administration/log-management/search-fields/features/add-or-manage-search-field/#test-your-expression
[XPath]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/xpath/
[XPath on Message Context]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/xpath-on-message-context/
[XPath on Wrapped XPath]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/xpath-on-wrapped-xpath/