Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Regex for matching email addresses
^[\w.%+-]+@(?:[\w-]+\.)+[A-Za-z]{2,4}$
Explanation:
^ # Start of string. If searching in-line replace with \b
[\w.%+-]+ # Matches alphanumeric, _, ., %, +, or - repeatedly
@ # name-domain separator
(?:
[\w-]+ # Matches alphanumeric or - repeatedly
\. # Matches dot in domain separator
)+ # Matches for one domain or for multiple subdomains
[A-Za-z]{2,4} # Matches top-level domain, no more than four characters
$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.