Skip to content

Instantly share code, notes, and snippets.

@gregseth
Last active December 10, 2025 22:39
Show Gist options
  • Select an option

  • Save gregseth/5582254 to your computer and use it in GitHub Desktop.

Select an option

Save gregseth/5582254 to your computer and use it in GitHub Desktop.
RegEx for RFC 2822 compliant email address.

Complete version

(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\ x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])

Simpler version

[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?

Sources

@GregoryMaks

Copy link
Copy Markdown

There's a space that breaks complete regex version - [\ x01

@sinneren

Copy link
Copy Markdown

Error in link RegEx email.htlm -> email.html

@danielturus

Copy link
Copy Markdown

The complete version doesn't work. You can copy and try yourself.

@sonyarianto

Copy link
Copy Markdown

The complete version I try on regex101.com and I need to escape the / char

/[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/g

now works :)

@kuriel-trivu

kuriel-trivu commented Jul 21, 2022

Copy link
Copy Markdown

@sonyarianto you don't have to modify anything, just choose the right option:

image

@ZiiSolutions

Copy link
Copy Markdown

@kuriel-trivu
Where can I get access to those different flavours?
You got a url?

@MreeP

MreeP commented Oct 15, 2022

Copy link
Copy Markdown

@michael-freidgeim-webjet

Copy link
Copy Markdown

To support upper-case in the email regex a-z should be replaced with a-zA-Z

@MNF

MNF commented Dec 2, 2022

Copy link
Copy Markdown

The referred article https://www.regular-expressions.info/email.html suggests

This regex is intended to be used with your regex engine’s “case insensitive” option turned on

It should be mentioned at the top of this page

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment