我想得到“cat, bat, sat, fat”中的第二个“.at”'index,程序是:
var text = "cat, bat, sat, fat";
var pattern = /.at/g;
var matches = pattern.exec(text);
var num = 2;
var i = 0;
while(pattern.test(text)){
if(++i == num){
alert(matches.index);
break;
}
matches = pattern.exec(text);
}
正确的索引应该是 5,但是为什么我得到 10?
-_-