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

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

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

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

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

## :fa-triangle-exclamation: 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.*  

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

* :fa-plus: [Add or manage Search Field][]  
* :fa-flask: [Test Your Expression][]  
* :fa-list-check: [Allowed XPath expressions][]  
* :fa-table-list: [Add or manage Log View][]  

## :fa-link-horizontal: Related Topics

* :fa-magnifying-glass: [XPath][]  
* :fa-magnifying-glass: [XPath on wrapped XPath][XPath on Wrapped XPath]  
* :fa-magnifying-glass: [XPath on Message Context][]  
* :fa-magnifying-glass: [RegEx][]  
* :fa-magnifying-glass: [RegEx with capturing groups][]  
* :fa-function: [Formula xPath2][]  
* :fa-signs-post: [Choose a plugin][]  
* :fa-magnifying-glass-plus: [Search Field Expressions][]  
* :fa-magnifying-glass-plus: [Search Fields][]  
* :fa-file: [Message Types][]  
* :fa-table-list: [Log Views][]  

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

[Add or manage Log View]:{ndr}/Administration/1.%20Log%20Management/1.%20Log%20Views/Features/Add%20or%20Manage%20Log%20View.md
[Add or manage Search Field]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Add%20or%20manage%20Search%20Field.md
[Allowed XPath expressions]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Troubleshooting/Allowed%20XPath%20expressions.md
[Choose a plugin]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Overview.md#fa-signs-post-choose-a-plugin
[Formula]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Overview.md
[Formula xPath2]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Formula/Extract/xPath2.md
[How expressions run]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Overview.md#fa-gears-how-expressions-run
[Log Views]:{ndr}/Administration/1.%20Log%20Management/1.%20Log%20Views/Features/What%20is%20a%20Log%20View.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 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
[Test Your Expression]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Add%20or%20manage%20Search%20Field.md#test-your-expression
[XPath]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/XPath.md
[XPath on Message Context]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/XPath%20on%20Message%20Context.md
[XPath on Wrapped XPath]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/Search%20Field%20Expressions/Xpath%20on%20wrapped%20XPath.md