Created
June 17, 2011 17:42
-
-
Save dmkc/1031883 to your computer and use it in GitHub Desktop.
A mostly RFC822 compatible email address regex that captures just the email adress. Accepts addresses like "Jimi Hendrix" <[email protected]>, John Lennon <[email protected]>, "<[email protected]>" <[email protected]> and "anything &@#^" <va
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(?:(?:\"[^\"]+\"|[^@,\"]+)\\s+<(?=[^>]+>))?([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4})(?:>)? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will parse an email like "[email protected]>" as valid, but if capture group 1 is used all should be OK regardless. Alternatively, the email part could be copy and pasted to split the regex into two cases, one with the 'bare' email and one with the name part in front and the email surrounded by angled brackets, but for my current purposes I'm only using whatever is in group 1 and thus don't care. Regex in a lookbehind won't work for most regex engines and I can't think of another way off the top of my head.