The examples in this article describe the way JavaScript uses regexp to make regular matches. Share to everyone for your reference. The implementation method is as follows:
<script type= "Text/javascript" > var matchedtimes = 0;
Match one D followed by one or more B's followed by one D//remember matched B ' s and the following D//ignore case
Myre = new RegExp ("D (b +) (d)", "IG");
Equivalent to Myreg =/d (b +) (d)/ig; MyArray = Myre.exec ("Ecdbdsdbbdz");
Ecdbbdbsdbbdz console.log ("Regular Expression String:" + myre.source);
Console.log ("is global?" + Myre.global);
Console.log ("Ignore case?" + myre.ignorecase);
Console.log ("is Mulitiline?" + myre.multiline);
Console.log ("------------------------------------------------");
Loginfo (myarray, Myre);
MyArray = Myre.exec ("Ecdbdsdbbdz");
Loginfo (myarray, Myre);
function Loginfo (myarray, Myre) {matchedtimes++;
Console.log ("This are" + Matchedtimes + "Times match");
Console.log ("Original String:" + myarray.input);
Console.log ("Match result Array: [" + MyArray + "]");
Console.log ("The 0-based index of the match in the string:" + Myarray.index); Console.loG ("The Last matched characters:" + myarray[0]);
Console.log ("The parenthesized substring matches [1]:" + myarray[1]);
Console.log ("The parenthesized substring matches [2]:" + myarray[2]);
Console.log ("The index at which to start the next match:" + myre.lastindex);
Console.log ("-----------------------------------------------");
} myRe2 =/^\w+ (\d*) $/ig console.log ("myRe2:" + myre2.source);
Console.log ("MyRe2 matches ABC1?" + Myre2.test ("ABC1")); Plus this line run to see the result, because it is global match, so lastindex will change,//So the myre2.test of the Back ("ABC") is of course false Console.log ("MyRe2 matches ABC?" + myre2.t
EST ("abc"));
</script>
The
wants this article to help you with your JavaScript programming.