Pattern: Email address

“Email address” is one of the patterns that you can select on the Match panel. Use this pattern to make a field match an email address. You can set the pattern to allow any email address, or only email addresses for specific users or specific domains.

This example shows how you can use the “email” pattern to look for email addresses. You can find this example as “Pattern: email (any)” in the RegexMagic library.

  1. Click the New Formula button on the top toolbar to clear out all settings on the Samples, Match, and Action panels.
  2. On the Samples panel, paste in one new sample:
    support@regexmagic.com
    sales@regexmagic.com
  3. On the Match panel, set “begin regex match at” to “start of word”, and set “end regex match at” to “end of word”.
  4. Click the Add First Field button to add field 1.
  5. In the “pattern to match field” drop-down list, select “email”.



  6. Set the “field validation mode” to “average”.
  7. On the Regex panel, select “C# (.NET 2.0–4.8 & .NET Core 1.0–3.0)” as your application, turn off free-spacing, and turn off mode modifiers. Click the Generate button, and you’ll get this regular expression:
    \b[!#$%&'*+./0-9=?_`a-z{|}~^-]+@[.0-9a-z-]+\.[a-z]{2,63}\b

    Required options: Case insensitive.
    Unused options: Exact spacing; Dot doesn’t match line breaks; ^$ don’t match at line breaks; Numbered capture.

  8. The Samples panel now highlights the email addresses our regex matches:
    support@regexmagic.com
    sales@regexmagic.com

Specific Email Addresses

Generating a regex that matches any email address is trivial with RegexMagic. Then again, picking such a regex from an online library of regular expressions is trivial too. What you can do with RegexMagic’s email pattern that you can’t do with copy-and-paste from the web is to generate a regex that matches specific email addresses.

This second example continues from the one above. It shows how you can use the “email” pattern to look for specific email addresses. You can find this example as “Pattern: email (specific)” in the RegexMagic library.

  1. On the Match panel, set the “user name” option for the email pattern to “specific user names only”. Enter support as the user name we want.
  2. Set the “domain name” option for the email pattern to “any domain on specific TLDs”. Enter com as the top-level domain (TLD) that we want.



  3. Make sure the Generate button is still pressed on the Regex panel and you’ll get this regular expression:
    \bsupport@[.0-9a-z-]+\.com\b

    Required options: Case insensitive.
    Unused options: Exact spacing; Dot doesn’t match line breaks; ^$ don’t match at line breaks; Numbered capture.

  4. The Samples panel now shows that our regular expression only matches email addresses on the .com domain that have “support” as the user name:
    support@regexmagic.com
    sales@regexmagic.com

Related Examples

Reference