Simple parser/regex question

I’m sure this is super-simple for someone that knows what they’re doing…but I’m not a programmer and am stumped.

All I want to do is extract values from an email sent in a consistent format. I have the email webhook setup, which works fine… and have tried lots of combos of using the parser module…but don’t know what i’m doing!

in the email, it contains the following text:
We are pleased to confirm that your order has now been shipped.

Our Reference: 12345678
Your Reference: 87654321
Carrier: DHL Express
Carrier’s Reference: 61142T01234567890

all i want to do is pull out the values in each line.

Anyone kind enough to help a newb??

2 Likes

Hey @Noah

Here’s the regex you will need: (?<=Our Reference: )(.*)(?=)|(?<=Your Reference: )(.*)(?=)|(?<=Carrier: )(.*)(?=)|(?<=Carrier’s Reference: )(.*)(?=)

It will create multiple bundles, use aggregator to combine into one.

4 Likes

Excellent expression! Let’s make it a little more flexible to allow white space between the label and the actual value, as well as look for digits only for the our reference and your reference assuming only digits are allowed there. You can use regex as a pattern matching service that will be flexible enough to catch even formatting issues if you want but smart not to capture stuff that appears invalid. Up to you.

(?<=Our Reference:)\s*(\d*)(?=)|(?<=Your Reference:)\s*(\d*)(?=)|(?<=Carrier:)\s*(.*)(?=)|(?<=Carrier’s Reference:)\s*(.*)(?=)

3 Likes

@Noah

This is fun!

How about one that doesn’t require an additional module? These are presented in a Set multiple variables module; but you could just use the expressions wherever you want the values:

Here are the expressions:
{{replace("X"; "/(?:.|\s)*Our Reference:\s*(\d*)(?:.|\s)*/"; "$1")}}
{{replace("X"; "/(?:.|\s)*Your Reference:\s*(\d*)(?:.|\s)*/"; "$1")}}
{{replace("X"; "/(?:.|\s)*Carrier:\s*(.*)(?:.|\s)*/"; "$1")}}
{{replace("X"; "/(?:.|\s)*Carrier.s Reference:\s*(.*)(?:.|\s)*/"; "$1")}}

Of course, replace “X” with the actual text reference.


Jim - The Monday Man (YouTube Channel)
What is Make & How can it help you with monday?
We Create Custom Solutions - Your Make or Ours
Schedule a 1-on-1 Tutorial Session (for monday, Make or Excel)

4 Likes

@JimTheMondayMan very cool use of replace with regular expressions.

I like your use of prefixed white space and other characters before the labels in the lookbehind (?:.|\s) – very nice addition.

But a point of contention on the use of “an extra module” – your Set Multiple Variables uses an operation just like the Text Parser would so I am not sure this approach would save any operations.

Also the text parser tool has been updated and supports “named” groups now so an expression like

(?<number1>\d+) and (?<number2>\d+)

for the text string

this is 1234 and 5678

generates this output bundle

image

You can see the text parser effectively sets the necessary variable names for use in subsequent modules.

2 Likes

This is fantastic input guys…really appreciate it!! was knocking my head against the wall for a while, but now I see how this works with your help!

2 Likes

@Noah I think along with the array aggregators and iterators, routers and effective use of the core Make functions, learning Regular Expressions is absolutely a terrific investment in time. RegEx’s have been around for decades and are most definitely a “secret sauce.”

3 Likes

@alex.newpath

I don’t disagree that the Text Parser has its advantages. But as I stated in my post, the Set multiple variables module is not needed.


Jim - The Monday Man (YouTube Channel)
What is Make & How can it help you with monday?
We Create Custom Solutions - Your Make or Ours
Schedule a 1-on-1 Tutorial Session (for monday, Make or Excel)

2 Likes

Jim, you sure have a love for regular expressions!