What would be the regular expressions to extract the name and email from strings like these?
johndoe@example.com
John <johndoe@example.com>
John Doe <johndoe@example.com>
"John Doe" <johndoe@example.com>
It can be assumed that the email is valid. The name will be separated by the email by a single space, and might be quoted.
The expected results are:
johndoe@example.com
Name: nil
Email: johndoe@example.com
John <johndoe@example.com>
Name: John
Email: johndoe@example.com
John Doe <johndoe@example.com>
Name: John Doe
Email: johndoe@example.com
"John Doe" <johndoe@example.com>
Name: John Doe
Email: johndoe@example.com
This is my progress so far:
(("?(.*)"?)s)?(<?(.*@.*)>?)
(which can be tested here: http://regexr.com/?337i5)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…