lastIndex RegExp对象的读/写属性。对于设置了" g"属性的正则表达式,它包含一个整数,该整数指定紧随RegExp.exec()和RegExp.test()方法找到的最后一个匹配项之后的字符位置,这些方法使用此属性作为它们进行下一次搜索的起点。
RegExp.prototype.sticky - 语法
RegExpObject.lastIndex
RegExp.prototype.sticky - 返回值
返回一个整数,该整数指定最后匹配之后的字符位置。
RegExp.prototype.sticky - 示例
var str="Javascript is an interesting scripting language"; var re=new RegExp( "script", "g" ); re.test(str); console.log("Test 1 - Current Index: " + re.lastIndex); re.test(str); console.log("Test 2 - Current Index: " + re.lastIndex)
运行上面代码输出
Test 1 - Current Index: 10 Test 2 - Current Index: 35
参考链接
https://www.learnfk.com/es6/regexp-prototype-sticky.html
标签:Index,无涯,sticky,Current,re,RegExp,prototype From: https://blog.51cto.com/u_14033984/9638858