Regex patter for extracting first and last name from email


that is the email, I want to extract the name, email, phone and location from it.

I found 2 regex patterns so far for email and phone
email= ([a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+.[a-zA-Z0-9_-]+)
phone= (([+][(]?[0-9]{1,3}[)]?)|([(]?[0-9]{4}[)]?))\s*[)]?[-\s.]?[(]?[0-9]{1,3}[)]?([-\s.]?[0-9]{3})([-\s.]?[0-9]{3,4})

what regex pattern can I use to extract name and location, also is the one above right?

Hi,

In this case, I recommend to use lookbehind of regex as the following.

System.Text.RegularExpressions.Regex.Match(yourString,"(?<=EMAIL:\s*)\S+").Value

System.Text.RegularExpressions.Regex.Match(yourString,"(?<=CALL:\s*)\S+").Value

System.Text.RegularExpressions.Regex.Match(yourString,"(?<=Location:\s*).+").Value

And can you share which part do you want to extract as Name?

Regards.

Thanks mate for that info.

so want to extract the name from that

Hi,

How do you want to extract these items from an email?
Do you already have mail body as string using GetOutlookMailMessage activity etc? if so, can you share the string?
Or
Do you want to extract these items from web browser directly?

Regards,

Hey, so I am using Integromat to extract the data from specific emails that come to my inbox

Here is the screenshot of the automation on Integromat

Hi,

The expressions in my previous post is for .net. As regex is slight difference b/w language, perhaps you need to use regex for your system.
And as we cannot know how table in mail body is handled, it’s necessary to clarify its specification.
So. it might be better to ask those in community of the system.

FYI, Pattern in the above image should be not System.Text.RegularExpressions.Regex.Match(yourString,"(?<=EMAIL:\s*)\S+").Value but just (?<=EMAIL:\s*)\S+

Regards,

Thanks for your input


so I used a mail hook and that screenshot shows how the data is being received by the system, will the regex pattern you shared work here? or show I use a different regex pattern

HI,

Alright. For now, can you try the following pattern?

(?<=First Name\n).*

or

(?<=First Name\r\n).*

Basically (?<=KEYWORD\n).* might work.

Regards,

Thanks Yoichi, will try that out.

so for email, it can be (?<=Email\n).*
& phone number can be (?<=Phone\n).* right?

also both emails and phone have the same thing repeated in brackets, should that be of any concern?

HI,

We can check the pattern works or not in online regex tester such as https://regex101.com/
Please check your actual text and the pattern in advance.

Regards,

Thanks, I just did and as suspected, for the email and phone, the bracket is coming along with it


what can I do to remove the one in the bracket

regards

Hi,

How about the following pattern?

(?<=Email\n)[^<]+

Regards,

Thanks, btw I tested them out in regex and all the patterns worked, but when I tested them in the tool (Integromat) it didn’t work, so I asked the community and they said something like this, do you know what they mean?

HI,

He says as the system doesn’t support positive lookbehind, you need to use grouping.
This means, the following pattern will work, for example.

Email\n([^<]+)

If there is settings for regex group number or name in the system, please try to set it.

Regards,

Thank you Yoichi, that worked in the tool.

anyways as the regex changed, what should the ones for name, phone and location be?
I tried to figure it out based on the email one you gave but couldn’t create one.

This is the data for reference

HI,

Can you try as the following?

First Name\n(.+)

If there is 2 linebreaks between title and data, the following might be better.

First Name\n+(.+)

Regards,

Thank you mate, it worked.
The email and phone had 2 linebreak but I added a + like you did here and it got dissolved.

One last question, I used this regex- Location\n+(.+)
to extract location data but didn’t work, do you know why

image

H,

Because there is no linebreak. In this case, Location:(.+) or Location:\n*(.+) will work.

Regards,

Thank you so much mate, will come back to this forum in the future, In case no one told you this, you are awesome.

Btw I also want to learn regex patterns for extracting data, I don’t have a programming background what would you suggest I do to learn em

Hi,

There are some tutorials regarding regex for UiPath user as the following, for example. Probably it will help you.

Or as i mentioned in previous post, there are slight different syntax for regex among language, it might be better to learn regex for your focused language.

Regards,