Skip to content

Instantly share code, notes, and snippets.

@sureshnath
Created April 10, 2015 09:48
Show Gist options
  • Save sureshnath/5160762772bc0aa58be4 to your computer and use it in GitHub Desktop.
Save sureshnath/5160762772bc0aa58be4 to your computer and use it in GitHub Desktop.
email regex
[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\b
https://regex101.com/
/[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\b/
[A-Za-z0-9._%-]+ match a single character present in the list below
Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
A-Z a single character in the range between A and Z (case sensitive)
a-z a single character in the range between a and z (case sensitive)
0-9 a single character in the range between 0 and 9
._%- a single character in the list ._%- literally
@ matches the character @ literally
[A-Za-z0-9.-]+ match a single character present in the list below
Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
A-Z a single character in the range between A and Z (case sensitive)
a-z a single character in the range between a and z (case sensitive)
0-9 a single character in the range between 0 and 9
.- a single character in the list .- literally
\. matches the character . literally
[A-Za-z]{2,4} match a single character present in the list below
Quantifier: {2,4} Between 2 and 4 times, as many times as possible, giving back as needed [greedy]
A-Z a single character in the range between A and Z (case sensitive)
a-z a single character in the range between a and z (case sensitive)
\b assert position at a word boundary (^\w|\w$|\W\w|\w\W)
@samirfor
Copy link

samirfor commented Aug 6, 2015

Thanks :)
But:
s@s.com@s.com WAS MATCHING

so I only added ^ and $ to match only once:

^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\b$

now its ok. Thanks @pedrohills

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