Need to extract information from a email messages . Need help with the regex pattern /expression

What are you trying to achieve?

I’m trying to pull a set specific data from each email notification that I receive, and insert on 3 colums on a googlesheet . but I’m not a coder and believe that I need the text parser module. I want to extract a part of an email i recieve and put it in a row in googles .

Steps taken so far

I have set you the scenairo but i dont know how to get the regex pattern for my text parser . Its so confusing
Manual SMS Specical - Google Sheets . this is how i need the final page to be like

This regular expression may be what you want:

(.+?)\sto\s(\d+)\sReference\sID\sIs\s:\s#(\w+)

You can check it here with your data:

L

1 Like

When reaching out for assistance with a regex pattern for a Text Parser module, it would be super helpful if you could share the actual text you’re trying to match. Screenshots of text can be a bit tricky, so if you could copy and paste the text directly here, that would be awesome! It ensures we can run it against test patterns effectively. If there’s any sensitive info, feel free to change it to something fictional yet still valid by keeping the format intact.

Providing clear text examples saves time on both ends and helps us give you the best possible solution. Without proper examples, we might end up playing a guessing game, and nobody wants that as it is a waste of time! You are more likely to get a correct answer faster. So, help us help you by sharing those text snippets. Thanks a bunch!

samliewrequest private consultation

Join the Make Fans Discord server to chat with other makers!

1 Like

Thanks so much expressison work like magic … I am sorry but there is another type of email also that also comes

Notification Alert

Hi, staffdd Funded Opat (taiwoopaleye@gmail.com) With 1950 Naira. Reference ID Is : #NSWZUCCDG2LPYTCJ

If you wish to option out from this kind of mail, please contact us or ignore this message.

On the same sheet i have shown how what i want extracted from theese types of mails .
My question is do i have a single expression for both types of emails or do i have 2 different email parsers ??

Thanks so much for your help

If you can change the regular expression to handle both cases, you can try that. However, it might not be possible and in that case you would need two parsers.

That said, once a module consumes the data, that data is no longer available. You need to take a different approach of you want to handle the data once and have different paths depending on the inpuut.

If you search for the magic router formula, you will see how that can achieved and maybe you can adapt it to your specific situation.

L

Oh, I hadn’t seen @samliew’s response on my phone. He’s the one with the magic router formula.

L

how do i change the regular expression to handle both cases.
shina

Well, the easiest way is to give the information to ChatGPT or Claude or… and tell it what you want. That’s how I fixed your regular expression.

You can tell it what you have as a regular expression, what it does, and what you are trying to accomplish, Something like this:

I have this regular expression:

YOUR REGEXP

to parse this text:

YOUR TEXT

so I can extract these elements:

THE STUFF YOU’RE GETTING

I would like to extend the regexp so it can also parse this text:

YOUR TEXT

and extract these elements:

THE ELEMENTS YOU WANT

Then, when it give you the regexp, test it in pythext to make sure it works and include it in your flow.

L

Thanks so much for your help , Been spending the whole day trying to use chatgpt to get the regex expesssion but i keeo getting errors in my flow . i am still forced to come back for help

My email content is this

Notification Alert

Hi Admin,
SamlizwillGlobal wants to buy data on app.discountdata.ng
MTN SMESPECIAL 10GB - 100 Days | Mega Plan @N240 to 07033466356
Reference Number: 2024070414179454a6a83368d86c

If you wish to option out from this kind of mail, please contact us or ignore this message.

The samples of what i am trying t extract is like this google sheet

I really do appreciate your help and i wish i can use this text pharser on my own with having to bother you all the time .

Thanks so much for help . you are were really helpful for me and i was able to use your regex
Please help me .this is the email text

Notification Alert

Hi Admin,
SamlizwillGlobal wants to buy data on app.discountdata.ng
MTN SMESPECIAL 10GB - 100 Days | Mega Plan @N240 to 07033466356
Reference Number: 2024070414179454a6a83368d86c

If you wish to option out from this kind of mail, please contact us or ignore this message.

and this is what i am trying to extract as shown in this google sheet

Thanks so much in advance

If your messages are drastically different, creating a single regexp to resolve everything will be pretty difficult. You might need to use a filter and a router to create multiple instances of a regexp parser, each to handle a specific type of message.

For your specific message, it would be good to share what you’ve found so far so we can point you in the right direction.

So, I messed around with it a bit and this regexp might do the trick:

(?s)Notification Alert.*?(\w+)\s+wants to buy data.*?\n(.*?@.*?to (\d{11}).*?Reference Number: (\S+)).*?If you wish

That said….

Regexp might not be the best way to do this. Instead, you could try to ask ChatGPT to give you the information. Create a prompt that contains all the information you need to parse the various messages you get. Then, ChatGPT should be able to learn from the examples and you can add to them every time you have a different type of notification message.

Of course, there is a cost associated with every call you make to ChatGPT, so you’ll need to factor that in your decision.

In the end, to get the regexp I gave you, I used Claude Sonnet 3.5 instead of ChatGPT.

I told it what I wanted then every time it gave me a regexp, I put it in pythex, and I told it what was matching and what wasn’t. Then Claude refined the regexp until I got the answer above. You can use the same approach if you need another regexp.

L

Hello ,
Its not work work . I got the following error.
the operation failed with an error. Invalid regular expression: /(?s)Notification Alert.?(\w+)\s+wants to buy data.?\n(.?@.?to (\d{11}).?Reference Number: (\S+)).?/: Invalid group

The email is

Discount Data - Nigeria's topmost enterprise solution to your telecom needs.
Notification Alert

Hi Admin,
Opotaki wants to buy data on app.discountdata.ng
MTN SMESPECIAL 10GB - 100 Days | Mega Plan @N240 to 08108921549
Reference Number: 202407031614d094ccfda91690ce

If you wish to option out from this kind of mail, please contact us or ignore this message.

If you face any issues, please contact us at help@discountdata.ng

(c) 2024 Discount Data. All rights reserved.

This email was sent to you as a registered member of Discount Data. Thank You. 

I am trying to extract the following as shown on this google sheets

I need the
Date USERNAME Transaction Plan Phone Number Refrence

thanks so much . I really appreciate your help
shina

You have multiple lines that don’t all look the same in the Google sheet… What is the correct version? It looks like the first one is the only correct one, but I’m not sure.

L

I took another stab at it, and this is what seems to work with the email you provided:

(?:[\s\S]*)Notification Alert[\s\S]*?(\w+)\s+wants to buy data[\s\S]*?\n([\s\S]*?@[\s\S]*?to (\d{11})[\s\S]*?Reference Number: (\S+))[\s\S]*?If you wish

Hopefully that regexp and the hints I gave before will help you create new ones as needed. Note that the reason the first one didn’t work is because I was using the wrong version of regexp syntax. When I read the documentation(!), I figured out my error.

Once again, I did troubleshooting in ChatGPT, and (this time) I tested the result before posting. :slight_smile:

image

L

1 Like