Using RegEx to get various email addresses

Hi all

I’ve got a project where I have to get email addresses and have realised that using the Matches activity in a For Each loop will probably be best

Here are example email addresses that cover all permutations

The reg-ex I have written covers all but the last one with the hyphens in

^([A-Za-z.\d].?[A-Za-z])(@[A-Za-z].[A-Za-z].?[A-Za-z]*)$ (this doesn’t look like Ui Path is showing this right so have included a screenshot)

The thinking being I’ve used ‘A-Z’ instead of \w to stop email addresses being picked up where somebody has put in incorrect symbols

Please can somebody see if they can alter the above so the last email address with the hyphens in is picked up? When I have added a ‘-’ to the first character set, this hasn’t worked.

Thanks all,

You are as close as i was (same thinking).
Maybe try something like this

1 Like

Cool, that’s worked fine :slight_smile: thanks @srdjan.suc

I’ve modified it slightly to, to prevent people putting in symbols by mistake or typing after the email address has ‘ended’



1 Like

UiPath has a ‘Matches’ activity. extremely useful. Regex but made easier. Try it


Hey @srdjan.suc

Please can I ask if you know for this positive lookahead which looks for the an ‘a’ which is followed by an ‘r’, how I would modify this so it only picks out the first ‘a’ in car and none of the others?



You’ll have to be more specific. Do you want it to always get the first occurrence? If so just use the matches activity and use matches(0) or regex.match (which takes the first match only by default).

What happens if the word character is in there?

This is a character car car car

Do you want it to find the a in the word car or the a in character?

1 Like

I agree with Dave, you can use RegexResult(0) to get the first value. (it is much easier than writing more complex Regex).

But if you are specific, maybe we can write some Regex for your needs

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