This question already has answers here: Why does a RegExp with global flag give wrong results? (7 answers) Closed 4 years ago .

Can anyone explain why the alert() in the following JavaScript code is firing? It appears to be a bug in the RegExp.test() method which reverses its previous decision each time you run the method. I'm using IE7.

I've found a replacement that appears solid, using the string.search(regex) method instead. But, I'm curious whether anyone knows something about this.