Why does Javascript's regex.exec() not always return the same value?
===

In the Chrome or Firebug console:

    reg = /ab/g
    str = "abc"
    reg.exec(str)
       ==> ["ab"]
    reg.exec(str)
       ==> null
    reg.exec(str)
       ==> ["ab"]
    reg.exec(str)
       ==> null

Is exec somehow stateful and depends on what it returned the previous time? Or is this just a bug? I can't get it to happen all the time. For example, if 'str' above were "abc abc" it doesn't happen.