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

Posted on 2014-07-10
Last Modified: 2014-07-10
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:

but would also match:


and would not match:

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


Question by:Alan3285
    LVL 34

    Accepted Solution

    If you'd like to go into great detail about what to try to match, there's a great article on the topic here:

    The recommended email matching pattern from that article, which is intended to keep things simple, is:

    Open in new window

    (it's assumed an ignore-case option is turned on, so lower case  characters can also be matched)

    That pattern would match all your examples, except for the one with the single quote. To allow that too, it would need to be adjusted to:

    Open in new window

    If you view the more complicated (and strictly more correct) patterns in the article, you'll understand why keeping things simple is desirable!
    LVL 12

    Author Closing Comment

    Looks good to me!

    Thank you,


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
    As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now