Link to home
Start Free TrialLog in
Avatar of Alan
AlanFlag for New Zealand

asked on

RegExp - Matching email addresses that could be well mixed into other text

Hi All,

I have some VBA code that I am using to find email addresses in email bodies in Outlook (the full code can be found in another question linked here, but you probably only need to know what is posted in this question - I am referencing for completeness and context).

The code is now working as expected, but I need to work on the RegEx.

This is what I am using currently:

MyPattern = "\b\w*@\w*\.\w*\.\w*\b|\b\w*@\w*\.\w*\b"

It was pointed out in the other thread that this would match:

alan@example.com
alan@example.co.nz
alan_3285@example.com

but would also match:

@.
1@2.3.

and would not match:

alan.3285@example.com
alan_o'leary@example.com
alan-3285@example.com


So, I need to try and find an expression that will solve those cases too.

Thanks,

Alan.
ASKER CERTIFIED SOLUTION
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Alan

ASKER

Looks good to me!

Thank you,

Alan.