Skip to content

Instantly share code, notes, and snippets.

@pswaminathan
Created October 3, 2013 21:43
Show Gist options
  • Save pswaminathan/6817593 to your computer and use it in GitHub Desktop.
Save pswaminathan/6817593 to your computer and use it in GitHub Desktop.
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