regex.test() only works every other time

后端 未结 1 1879
故里飘歌
故里飘歌 2020-12-25 11:03

Regex test() is giving me issues in Firefox and Chrome, yet it works flawlessly in Opera and Safari.

troubled code:

var pattern = /(\\s+         


        
相关标签:
1条回答
  • 2020-12-25 11:36

    It's a bug in the RegEx engine, a similar question with the same issue came up here.

    From my answer to that question: It's a bug with the way regexes are implemented in ECMAScript 3, there's a great post on the details here.

    The basics are a /regex/ with the g modifier doesn't reset correctly, so multiple .test() calls alternate between true and false if everyone should be true, every other calls successfully resets it.

    0 讨论(0)
提交回复
热议问题