var str = "123#abc";
var re = /abc/ig;
console.log(re.test(str)); //输出ture
console.log(re.test(str)); //输出false
console.log(re.test(str)); //输出ture
console.log(re.test(str)); //输出false
var str = "123#abc";
var re = /abc/ig;
console.log(re.test(str)); //输出ture
console.log(re.lastIndex); //输出7
console.log(re.test(str)); //输出false
console.log(re.lastIndex); //输出0
console.log(re.test(str)); //输出ture
console.log(re.lastIndex); //输出7
console.log(re.test(str)); //输出false
console.log(re.lastIndex); //输出0
referenece:http://www.cnblogs.com/rentj1/archive/2011/04/26/2029872.html
本文探讨了JavaScript中正则表达式的使用,特别是如何利用lastIndex属性进行字符串匹配。通过实例展示了当使用全局搜索标志(g)时,lastIndex如何影响正则表达式的后续匹配行为。
983

被折叠的 条评论
为什么被折叠?



