Struggling with Regex

Hi - I have this Regex(?=>From:)*([A-z0-9._%±]+@[A-z0-9.-]+.[A-z]+) that I am using on an email forwarded to the bot from an outlook rule. Therefore, the body of the email has the original email name I need to use for replies such as

From: Test User “<“”>”
Sent: Monday, February 13, 2023 4:48 PM
To: SVC_RPA_NP_BOT1 “<“”>”
Cc: Original User “<“”>”

Challenge is I want ONLY the From and the number of characters can vary for the preceeding name before the first < and there could also be digits. What I have built so far captures all of the <> groupings and I only want the From: grouping…Ideas?

I am assuming you are reading emails using ‘Get Outlook Mail Messages’ activity.
This should give you a collection of MailMessage objects which you then iterate with a for loop.

The mailmessage object will give you access to all the attributes of the email.
For Each message in listOfMessages
Assign → sender = message.From.ToString
There is also message.Sender object. See which one gives you the correct email address you’re looking for.

I hope this helps.

that is too much coding - would rather keep it simple with a regex…I already coded in your idea and although it is feasible it is not the route I want to go

Thank you, however

I am trying to make a regex. give me few moments.

Hi Chris

Personally I like regex but would follow the suggestion from @raja.arslankhan

However if you need/pefer to use Regex here is a regex pattern you could use.

Hopefully this helps,



1 Like

Thanks Steve - I typically don’t get stuck on Regex that often and this one may be down a rabbit hole in my brain. Your Regex works but the challenge is eliminating the value before the first < where that value can be a mixture of numbers or characters or non character items and at the same time limiting it to the From: row. And I may have over-complicated what I am doing by trying different things.


Try this regex pattern out in an assign:

system.Text.RegularExpressions.Regex.Match(yourStrEmail, “(?<=From:)(.+.<.)(.+@.+)(?=.>.)”).Groups(2).ToString

Quote marks are tricky combined with emails (which have a big regex pattern) I have tried to simplify using groups.

Hopefully this helps :blush:



Thanks again Steve but not the solution…I think my brain has simply over-complicated this today - it is my third automation today…maybe that means I need to step away…lol

1 Like

Actually - playing with the group idea…might be able to make that work…thanks for turning my brain in that direction…will let you know when I figure it out…I am stubborn

1 Like

Good to hear,

I can be stubborn to :rofl:

Check this regex pattern - no groups :blush:

system.Text.RegularExpressions.Regex.Match(yourStrEmail, “(?<=From:.+.\<.).+@.+(?=.\>.)”).ToString

Too early in the morning for me

Hopefulyl this helps :blush:

man gotta love the tenacity of Outlook…I am giving up for the day…back at it tomorrow. Steve - you have a fantastic day!

I solved this with a different regex

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.