javascript 正则表达式相关应介绍(2)


var str = "1Visit W3School, W3School is a place to study web technology.";
var patt = new RegExp("W3School","g");
var result ;
result = patt.test(str);
alert(result); //true
result = patt.test(str);
alert(result); //true
result = patt.test(str);
alert(result); //false


IE9+ 、较新版本的 chrome、firefox 中 , str.match(reg) 执行完毕后,无论是否全局匹配,是否存在匹配结果 ,lastindex 被重置,reg.lastIndex = 0 , reg.test(str) 执行后,如果正则是非全局匹配的,lastindex 被重置, re.lastIndex = 0 在 IE8 及以下,正则匹配执行后除非没有匹配结果,否则 re.lastIndex 是最后一个匹配字符串的结尾字符的位置 +1,即lastIndex 没有被重置

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wddfjf.html