Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
190
rated 0 times [  197] [ 7]  / answers: 1 / hits: 46119  / 12 Years ago, mon, january 21, 2013, 12:00:00

I'm having the this text below:



[email protected], assdsdf <[email protected]>, rodnsdfald ferdfnson <[email protected]>, Affdmdol Gondfgale <[email protected]>, truform techno <[email protected]>, NiTsdfeSh ThIdfsKaRe <[email protected]>, akasdfsh kasdfstla <[email protected]>, Bisdsdfamal Prakaasdsh <[email protected]>,; milisdfsfnd ansdfasdfnsftwar <[email protected]>


Here emails are seprated by , or ;.
I want to extract all emails present above and store them in array. Is there any easy way using regex to get all emails directly?


More From » jquery

 Answers
23

Here's how you can approach this:


HTML


<p id="emails"></p>

JavaScript


var text = '[email protected], "assdsdf" <[email protected]>, "rodnsdfald ferdfnson" <[email protected]>, "Affdmdol Gondfgale" <[email protected]>, "truform techno" <[email protected]>, "NiTsdfeSh ThIdfsKaRe" <[email protected]>, "akasdfsh kasdfstla" <[email protected]>, "Bisdsdfamal Prakaasdsh" <[email protected]>,; "milisdfsfnd ansdfasdfnsftwar" <[email protected]> datum eternus [email protected]';    

function extractEmails (text)
{
return text.match(/([a-zA-Z0-9._+-]+@[a-zA-Z0-9._-]+.[a-zA-Z0-9._-]+)/gi);
}

$("#emails").text(extractEmails(text).join('n'));

Result


[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected]



Source: Extract email from bulk text (with Regular Expressions, JavaScript & jQuery)


Demo 1 Here


Demo 2 Here using jQuery's each iterator function


[#80728] Saturday, January 19, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
elmer

Total Points: 432
Total Questions: 96
Total Answers: 107

Location: Jordan
Member since Wed, Jun 17, 2020
4 Years ago
;