- 5 minutes to read

RegEx with capturing groups search field expression type plugin

Use this plugin to extract values from small messages

The Nodinite RegEx with capturing groups Search Field Expression Type plugin can be used to match/style one or more unique values from payload in your logged documents.

  • Flat files
  • EDI/X12
  • XML

A Logged message comes from a Log Event that is part of the Logging feature of Nodinite and the Search Fields are further used within self-service enabled Log Views for your business.

Quick example

Let's get you started with the following simple demonstration example valid for this search field plugin. For other and more advanced examples please scroll down on this page to the Examples section.

Input Expression Result
<ns0:Orders xmlns:ns0="Common.Schemas/Nodinite/1.0">
    <Order>
        <Id>101</Id>
        <Amount>1337</Amount>
        <City CityId="054">Karlstad</City>
    </Order>
    <Order>
        <Id>102</Id>
        <Amount>10</Amount>
        <City CityId="08">Stockholm</City>
    </Order>
</ns0:Orders>
CityId="([0-9]+)"
054
08
XML Data RegEx expression Unique values

Features

  • Extract single or multiple unique values from messages (payload)
  • Use any RegEx expression to match and/or style data
    • Use additional options to further refine the output like the use of capturing groups, Global and Multi line

This plugin loads the entire message into RAM, so make sure to apply this extraction method on smaller messages only


How to use

To extract values from XML messages you must first configure the Search Field, in this example case; The City Id:

Once a Search Field is configured, values are extracted either during normal processing or from user initiated re-index operations. Extracted values are persisted and stored for as long as the days to keep events property on the Message Type is configured.

Test Expression

You can test an expression when configuring a Search Field in the 'Test Expression' tab

  1. Enter an appropriate payload in the 'Message Body' tab
  2. Select the 'RegEx with capturing groups' expression type plugin
    SelectPlugin
  3. Enter valid configuration (You can also click on elements/attributes to get a suggestion)
    • RegEx expression - The valid RegEx expression to match data
    • RegEx groups - Enter number or name of RegEx Group(s) to return (leave empty for all matches)
    • Global - When checked do not return on first match
    • Multi line - When checked use either ^ for start of line and $ for end of line
  4. Review result/output, rewrite the code in step 3 until you get the data you seek

The actual result (values) are extracted by the Logging Service and then presented together with the evaluated processing state and the number of unique matches.

Test Expression
Valid expression with state output, unique values and total count

If the expression is either invalid or does not match any data, then the following output is presented:
NoResult
Invalid expression yields no result

Examples

graph LR subgraph "Search Fields" sf(fal:fa-search-plus Order Number) end subgraph "Search Field Expressions" sfe(fal:fa-flask RegEx with capturing groups plugin) end subgraph "MessageTypes" mt1(fal:fa-file Orders) end sf --- sfe sfe ---|Expression configuration| mt1

Example sample #1: XML

To extract city id(s) from the message type Common.Schemas/Nodinite/1.1#Orders you can use the following valid expression CityId="([0-9]+)" and group 1. This expression extracts the values 054 and 08

Message Body

<ns0:Orders xmlns:ns0="Common.Schemas/Nodinite/1.1">
    <Order>
        <Id>101</Id>
        <Amount>1000</Amount>
        <City CityId="054">Karlstad</City>
    </Order>
    <Order>
        <Id>102</Id>
        <Amount>10</Amount>
        <City CityId="08">Stockholm</City>
    </Order>
</ns0:Orders>

RegEx configuration

CityId="([0-9]+)"
  • RegEx groups = 1
  • Global = Checked
  • Multi line - Unchecked

Example sample #2: Flat File (| Delimited)

To extract the 4th field, for example Customer Code from the following pipe (|) delimited flat file you can use the following valid expression ^(?:(.*?)\|){4} and RegEx Groups = 1. This expression extracts the value 456 and 789.

Message Body

ORD|101|ExampleCompany1|456|Company Name ACME |Dieselgate valley 1|123 45|Flameburg|
ORD|102|ExampleCompany2|789|Company Name MECA |Radiator Spring 420|543 21|Apocalypsenburg|

RegEx configuration

^(?:(.*?)\|){4}
  • RegEx groups = 1
  • Global = Checked
  • Multi line - Checked

FlatFileExample2
Example extract multiple customer codes from flat file


Example sample #3: Flat File (| Delimited with TAG/start of line)

To extract the 4th field, for example Customer Code from the following pipe (|) delimited flat file with at start tag KV you can use the following valid expression ^KV(?:(.*?)\|){4} and RegEx Groups = 1. This expression extracts the value 1337.

Message Body

ST|123
KV|Z|AN|1337|ABC123
ID|1912121212|

RegEx configuration

^(?:(.*?)\|){4}
  • RegEx groups = 1
  • Global = Checked or Unchecked (there is only 1 value matched in this example...)
  • Multi line - Checked

Example3
Example value from flat file with TAG KV


Example sample #4: Flat File (; Delimited with TAG/start of line)

To extract the 3rd field, for example Customer Code from the following (;) delimited flat file with at start tag HDR you can use the following valid expression ^HDR(?:(.*?)[;|\n|\r]){3} and RegEx Groups = 1. This expression extracts the value 42.

Message Body

HDR;ORDER;42
KV;Z;AN;1337;ABC123
ID;1912121212;

RegEx configuration

^(?:(.*?)\|){4}
  • RegEx groups = 1
  • Global = Checked or Unchecked (there is only 1 value matched in this example...)
  • Multi line - Checked

Example4



Next Step

How to Add or manage Search Fields
How to Add or manage Log Views

Expression Type Plugins are used in Search Fields
What are Search Fields?
What are Search Field Expressions?
What are Message Types?
What are Log Views?