問題:
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”,則不會發生。