A very simple regular expression test:
var regx = /^\d+$/g;
alert(regx.test("11") + ": " + regx.test("11"));
And the output is "true: false".
If I change to regx = new RegExp("^\\d+$", "g");
Then the output is the same.
This is the first weird part.
The second weird part is, when I only test the string once in a
function:
var regx = /^\d+$/g;
alert(regx.test("11") + ": ");
var regx = new RegExp("^\\d+$", "g");
alert(regx.test("11") + ": ");
If I call the function twice, the output will be
1st call:
true, true
2nd call:
true, false
My assumption is the global expression holds an internal status, but
that doesn't explain the second example.
Can someone help me out here please?