//==regexp===
1. The test () method of the regular expression
varresult;varstr = "Bcatasdsrtophe" ;varRe11 =/cat/g;//Match Catresult =re11.test (str);varRe12 =NewREGEXP ("Cat", "GI");//match Cat is case insensitiveresult =re12.test (str);varRe31 =NewRegExp (". he$");//A string ending with the Heresult =re31.test (str); alert (result);
Text = "000-01-2131";
var pattern41 =/\d{3}-\d{2}-\d{4}/;
if (pattern41.test (text)) {
Alert ("The Pattern was matched.");
}
//2. Regular expression exec () method
var text = "Mom and Dad and baby" ; var pattern =/mom (and dad (and)?)? /GI; var matches = pattern.exec (text); Alert (matches ); // mom and dad And,and Dad And,and
Input and Index property
var text = "Cat,bat,sat,fat"; var pattern1 =/.at/; var matches =//cat//0;index property, match in character creation position // Cat // Cat,bat,sat,fat;input Property, a string that applies a regular expression // 0
Pattern's global mode and non-global mode
var text= "Cat,bat,fat,sat"; var // Global Mode var matches; for (var i=0;i<4;i++= pattern2.exec (text); alert (matches+ "+Pattern2.lastindex);} // when global mode is used, each call to EXEC () returns the next occurrence in the string until the end of the string is searched. // and in global mode, the Lastindex property of the pattern increases after each call to exec () and remains unchanged in non-global mode.
JavaScript Learning Notes (iii)