Extract mail address from string using regex

Hi Experts

I need to extract the e-mail address from a filename string looking similar to this:

“Firstname Lastname mailaddress@contoso.com_3_Receiver.pdf”

The result should be “mailaddress@contoso.com” - can this be achieved by using regex?

1 Like

Use this Regex pattern in Match Activity.

[a-zA-Z0-9_.]+@[a-zA-Z0-9_.]+.[a-zA-Z.]+

To check this, use https://regexr.com/

image

2 Likes

check this out, this wil extract any type of email:
([a-zA-Z0-9_-.]+)@([a-zA-Z0-9_-.]+).(?=[\*])

1 Like

Hi @jacchr,

Considering this won’t be the only email ID format you get, I’ve prepared a regex for you which covers some possible and common formats:

([\w.]+)@([a-z.]+)(.)([a-z]+)

Regex

Note: the regex doesn’t match “jacchr.rpa@uipath” as it doesn’t have a period mark (.) after @

2 Likes

Thank you all for your reply.

Based on your input I have put it into the following regex command:

([\w.-]+)@([\w.-]+).([a-zA-Z]+)

I believe this should allow a-z, 0-9, . (period), _ (underscore) and - (hyphen) before and after @ and only a-z after the last . (period).