RegExp instance usage issue exec() method - Stack Overflow
phpcn_u1582
phpcn_u1582 2017-05-18 11:01:08
0
2
658
var text = "cat, bat, sat, fat";
var pattern2 = /.at/g;
var matches = pattern2.exec(text);
console.log(matches.index);   //0
console.log(matches[0]);   //cat
console.log(pattern2.lastIndex);   //3
matches = pattern2.exec(text);
console.log(matches.index);   //5,为什么是5,不应该从fat开始吗?
console.log(matches[0]);   //bat
console.log(pattern2.lastIndex);   //8

Why should we start from bat instead of fat?

phpcn_u1582
phpcn_u1582

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!