News for hackers. Stuff that matters.
Re:Javascript null surprise by tlrobinson on Friday February 22, 2008 @06:43PM (#121688)
How about this one...

    js> r = RegExp("asdf", "g"); 
    /asdf/g 
    js> r.test("asdf") 
    true 
    js> r.test("asdf") 
    false 
    js> r.test("asdf") 
    true 
    js> r.test("asdf") 
    false
Surprisingly this is not a bug, though I was certain it was at first. When using the global flag the RegExp object will keep track of the last matching character position and start the next comparison at that position (after the 4th character, in this case) which results in this seemingly incorrect alternation between "asdf" matching "asdf". Removing the global flag produces correct results.

There are no comments on this comment yet.