<! --
Frog frog recommendation: use regular expressions to search for emails
Ask the question: Give a string, find 5 emails, and highlight the emails in red (or other display modes ),
The five emails are saved as a string separated by commas and printed out.
-->
<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en">
<HTML>
<Head>
<Title> new document </title>
<Meta name = "generator" content = "editplus">
<Meta name = "author" content = "frog prince">
<Meta name = "keywords" content = "frog pond">
<Meta name = "Description" content = "">
<Script language = "jscript">
Function wawa_matchmail (STR)
{
/*
* --------------- Wawa_matchmail (STR )-----------------
* Wawa_matchmail (STR)
* Function: search for a substring that matches the mail format in a string, and return a new string that contains five searched mails separated by commas.
* Parameter: Str, string type, master string to be searched.
* Instance: wawa_matchmail ("only@sohu.com, DDD, only163.com ")
* Author: Tianji, frog prince
* Update:
* --------------- Wawa_matchmail (STR )-----------------
*/
// Here I use the match method of the string object.
VaR Re = // W + (-/W +) | (/. /W +) */@ [A-Za-z0-9] + ((/. |-) [A-Za-z0-9] + )*/. [A-Za-z0-9] +/g;
VaR M = mainstring. Match (re );
VaR M1 = ""
For (VAR I = 0; I <M. Length & I <5; I ++ ){
M1 + = m [I]. fontcolor ("blue") + ",";
}
Return (M1 );
}
Function wawa_replacemail (STR)
{
/*
* --------------- Wawa_replacemail (STR )-----------------
* Wawa_replacemail (STR)
* Function: search for a substring that matches the mail format in a string, generate a new string, and use red to represent the part of the email.
* Parameter: Str, string type, master string to be searched.
* Instance: wawa_replacemail ("only@sohu.com, DDD, only163.com ")
* Author: Tianji, frog prince
* Update:
* --------------- Wawa_replacemail (STR )-----------------
*/
// The political expression object and Regexp are used here.
VaR S = '';
// Var Re = new Regexp ("d (B +) (D)", "ig ");
VaR Re = // W + (-/W +) | (/. /W +) */@ [A-Za-z0-9] + ((/. |-) [A-Za-z0-9] + )*/. [A-Za-z0-9] +/g;
VaR J = 0;
While (ARR = re.exe C (STR ))! = NULL)
{
S + = Str. substring (J, (Regexp. lastIndex-RegExp.lastMatch.length ));
S + = Regexp. lastmatch. fontcolor ("red ");
J = Regexp. lastindex
// To familiarize everyone with the attributes of the regular expression object and Regexp object, I listed them. If you want to learn its usage, remove the comments to see the output.
// S + = "======================================== =====< br> ";
// S + = "$1 returns:" + Regexp. $1 + "<br> ";
// S + = "$2 returns:" + Regexp. $2 + "<br> ";
// S + = "$3 returns:" + Regexp. $3 + "<br> ";
// S + = "input returns:" + Regexp. Input + "<br> ";
// S + = "Index Returns:" + Regexp. index + "<br> ";
// S + = "lastindex returns:" + Regexp. lastindex + "<br> ";
// S + = "lastmatch returns:" + Regexp. lastmatch + "<br> ";
// S + = "leftcontext returns:" + Regexp. leftcontext + "<br> ";
// S + = "rightcontext returns:" + Regexp. rightcontext + "<br> ";
// S + = "lastparen returns:" + Regexp. lastparen + "<br> ";
// S + = "Arr. Index Returns:" + arr. index + "<br> ";
// S + = "Arr. lastindex returns:" + arr. lastindex + "<br> ";
// S + = "Arr. Input returns:" + arr. Input + "<br> ";
// S + = "re. lastindex returns:" + RE. lastindex + "<br> ";
// S + = "re. Source returns:" + RE. Source + "<br> ";
// S + = "======================================== =====< br> ";
}
S + = Regexp. rightcontext;
Return (s); // return results.
}
</SCRIPT>
</Head>
<Body>
<SCRIPT>
// Define the main string below
VaR mainstring = "frog prince, onlytiancai@sohu.com, 33, three points, guagua@wawa.cn ";
Mainstring + = "only@only.com, AD, 1234 <A> abcd@abcd.com @ ABC </a> sdfsdf feiyang@163.com ";
Mainstring + = "SDF sfd@msn.com.dsfsdf __# Co, I am a autumn tree zhang@yushang.com. Finished, haha ";
// Print the main string below
Document. Write ("original string:". Bold () + "<br>" + mainstring );
// Print the five searched emails below
Document. Write ("<br> 5 Emails:". Bold () + "<br>" + wawa_matchmail (mainstring ));
// Print below to replace the email with a red string
Document. Write ("<br> Replace the string with red:". Bold () + "<br>" + wawa_replacemail (mainstring ));
</SCRIPT>
</Body>
</Html>