问题:
This question already has an answer here: 这个问题在这里已有答案:
In the Chrome or Firebug console: 在Chrome或Firebug控制台中:
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? exec在某种程度上是有状态的,取决于它之前返回的内容吗? 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. 例如,如果上面的'str'是“abc abc”,则不会发生。