Here's a quickie version:
var textAreaVal = '"test" <[email protected]>,"test2" <[email protected]>,"test3" <[email protected]>';
// Better hope you don't have any "Smith, Bob"-type bits if you do it this way...
var textAreaLines = textAreaVal.split(",");
// Gonna assume you have jQuery here 'cause raw JS loops annoy me ;-)
// (if not you can hopefully still get the idea)
var emails = [];
$$.each(textAreaLines, function(index, value) {
var email = /<(.*?)>/.exec(value)[1];
if (email) emails.push(email);
});
// emails = ["[email protected]", "[email protected]", "[email protected]"]
The key is this line:
var email = /<(.*?)>/.exec(value)[1];
which essentially says:
var email =
// set email to
/<(.*?)>/
// define a regex that matches the minimal amount possible ("?")
// of any character (".") between a "<" and a ">"
.exec(value)
// run that regex against value (ie. a line of input)
[1];
// and use only the first matched group ([1])
You'll probably want to do a slightly more complex regex to account for any crazy input, ensure that there's a "@", or for people who just do ",[email protected]," (without the brackets), but hopefully you get the idea.