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

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.
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 |
| 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 |
For non-XML bodies, use RegEx or RegEx with capturing groups on the whole message; for the other plugins, see Choose a plugin.
Expression syntax
selects the element"] B --> C["RegEx to style value
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
XPath runs first (orange) on the body (blue); the RegEx (purple) runs on each selected value; the matches become the Search Field values (green).
The plugin shows these fields:
| Field | What goes in it |
|---|---|
| XPath | An XPath 1.0 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 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 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, 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.

Both checkboxes ticked on the Test Expression tab.

Selecting XPath with RegEx in the Type list.
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
<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
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.

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

Treat sub XML as a string, RegEx groups 1, and Global turned on: 2 unique matches, node1 and node2.
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:

No match: the test reports Processed with warning: The Expression yields no result instead of values.