AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



javascript-regex: How to find all emails present in a large text?

Please give me some way to extract the all emails present in a large text. I want to separate each email by new line.

javascript x 33
regex x 7
Posted On : 2014-04-18 00:10:14.0
profile Saksham Kumar - anyforum.in Saksham Kumar
73433939909
up-rate
5
down-rate

Answers


If you just want to do your task i.e. separating email id from a large text. Please click the below link to use our email separator. and You can choose any symbol as a separator.

Email Extractor Tool(click here)

and if you want to develop the email separator then following is the html and javascript code. Just copy it and paste it in a notepad and save it as html file.

Email-Extractor.html:
-------------------------------


<html>
<head><title>Email Extractor- AnyForum</title></head>
<body>
<script type="text/javascript">
function findEmail() {
var email = "No email address detected";
var a = 0;
var ingroup = 0;
var separator = document.extractor.sep.value;
var groupby = Math.round(document.extractor.groupby.value);

if (separator == "new") separator = "\n";
if (separator == "other") separator = document.extractor.othersep.value;
var rawemail = document.extractor.rawdata.value.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi); //match the email pattern in large text pasted in textarea.
var norepeat = new Array();
if (rawemail) {
for (var i=0; i<rawemail.length; i++) {
var repeat = 0;

// Check for repeated emails routine
for (var j=i+1; j<rawemail.length; j++) {
if (rawemail[i] == rawemail[j]) {
repeat++;
}
}

// Create new array for non-repeated emails
if (repeat == 0) {
norepeat[a] = rawemail[i];
a++;
}
}
if (document.extractor.sort.checked) norepeat = norepeat.sort(); // Sort the array
email = "";
// Join emails together with separator
for (var k = 0; k < norepeat.length; k++) {
if (ingroup != 0) email += separator;
email += norepeat[k];
ingroup++;

// Group emails if a number is specified in form. Each group will be separate by new line.
if (groupby) {
if (ingroup == groupby) {
email += '\n\n';
ingroup = 0;
}
}
}
}

// Return array length
var count = norepeat.length;

// Print results
document.extractor.count.value = count;
document.extractor.rawdata.value = email;
}
</script>
<FORM name="extractor">
<TABLE bgcolor="#CCCCCC" cellpadding=1 cellspacing=0 border=0>
<TR>
<TD>
<TABLE border=0 cellpadding=8 cellspacing=0 bordercolor="#000000" bgcolor="#CCCCCC">
<TR class="titlebarcolor">
<TD valign="TOP" colspan=2 ><h2 align="center"><FONT class="titlefont"><strong>Email
Extractor</strong></FONT></h2>
</TD>
</TR>
<TR>
<TD valign="TOP" align="CENTER" colspan=2>
<SCRIPT language="JAVASCRIPT">
var introtext = 'Copy text from any source and paste it into here. Then click extract button. You can select different separator (or enter your own), group a number of emails and sort extracted emails alphabetically.';
document.write('<TEXTAREA NAME="rawdata" rows=12 cols=50 onFocus="if (this.value == introtext) this.value = \'\';">' + introtext + '</TEXTAREA>');
</SCRIPT>
</TD>
</TR>
<TR>
<TD valign="TOP" align="LEFT" colspan=2> Separator:
<SELECT name="sep">
<OPTION value=", ">Comma</OPTION>
<OPTION value="|">Pipe</OPTION>
<OPTION value=" : ">Colon</OPTION>
<OPTION value="new">New Line</OPTION>
<OPTION value="other">Other</OPTION>
</SELECT>
<INPUT type="TEXT" name="othersep" size=3 onBlur="checksep(this.value)">
Group:
<INPUT type="TEXT" size=3 name="groupby" onBlur="numonly(this.value)">
Emails
<LABEL for="sortbox">
<INPUT type="CHECKBOX" name="sort" id="sortbox">
Sort Alphabetically</LABEL>
</TD>
</TR>
<TR valign="TOP">
<TD align="LEFT">
<INPUT name="BUTTON" type="BUTTON" class="button" onClick="findEmail()" value="Extract">
<INPUT name="RESET" type="RESET" class="button" value="Reset">
<SCRIPT language="JavaScript" type="text/javascript">

</SCRIPT>
</TD>
<TD align="RIGHT" valign="BOTTOM" nowrap> Email count:
<INPUT name="count" size=5 readonly>
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</FORM>
</body>
</html>

Posted On : 2014-04-18 00:21:18
Satisfied : 1 Yes  0 No
profile Garima Gupta - anyforum.in Garima Gupta
596129560202
Reply This Thread
up-rate
5
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in