why does my javascript regex.test() give alternating results
Posted
by Dennis George
on Stack Overflow
See other posts from Stack Overflow
or by Dennis George
Published on 2010-05-17T17:35:07Z
Indexed on
2010/05/17
17:41 UTC
Read the original article
Hit count: 191
var r = /\d/g;
var a = r.test("1"); // will be true
var b = r.test("1"); // will be false
console.log(a == b); // will be false
Please explain to me why the result of r.test("1") alternates with each call?
I was able to work around the issue I was having by removing the g modifier. However I would still like to understand why this happens.
© Stack Overflow or respective owner