> var p = /abc/gi;
> var s = "abc";
> p.test(s);
true
> p.test(s);
false;
When I run this code on console of Chrome I Have this output above. Each time I call .test() I get a different value. Someone could explain to me why this happens? thanks
The behavior is due to the “g” modifier, i.e. matches three times, no match the fourth time:
See similar question: Why RegExp with global flag in Javascript give wrong results?