İşte şipşak versiyonu:
var textAreaVal = '"test" <test@test.com>,"test2" <test2@test.com>,"test3" <test@test3.com>';
// 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 = ["test@test.com", "test2@test.com", "test@test3.com"]
Anahtarı bu satırı:
var email = /<(.*?)>/.exec(value)[1];
esas diyor ki:
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])
Muhtemelen umarım (parantez olmadan) "@", ya da sadece kişiler için ", bob@smith.com," var emin olun, herhangi bir deli giriş için hesap biraz daha karmaşık bir regex yapmak istiyorum, ama olacak Eğer fikir olsun.