JS正则表达式
var matches = pattern1.exec(text); console.log(matches.index); //0 console.log(matches[0]); //cat console.log(pattern1.lastIndex); //0 matches = pattern1.exec(text); console.log(matches.index); //0 console.log(matches[0]); //cat console.log(pattern1.lastIndex); //0 var pattern2 = /.at/g; var matches = pattern2.exec(text); console.log(matches.index); //0 console.log(matches[0]); //cat console.log(pattern2.lastIndex); //3 var matches = pattern2.exec(text); console.log(matches.index); //5 console.log(matches[0]); //bat console.log(pattern2.lastIndex); //8 复制代码 注意:IE的JavaScript实现lastIndex属性上存在偏差