I need to parse name and email address from a string of type
Ansh Aryan <ansharyan@mailinator.com>
Need a regex to be used in javascript for this purpose so that i get
name= Ansh Aryan
email = ansharyan@mailinator.com
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use the following regex:
Of course, if some deviation from that pattern should be allowed, you’ll have to tweak it to reflect it, but if not then it’ll be fine.
Some brief explanation of the regex:
([^<]+): Match and capture anything until a<symbol is found.\s: Match but don’t capture a single space token, which could be a space, a tab, or whatever.<(.*)>: Match the<...>and capture what is inside it.This will yield an array of
matches, wherematches[0]should be all the input,matches[1]the name, andmatches[2]the email you are looking for.