Regular expression test can't decide between true and false (JavaScript)

前端 未结 1 1363
广开言路
广开言路 2020-12-11 08:17

I get this behavior in both Chrome (Developer Tools) and Firefox (Firebug). Note the regex test returns alternating true/false values:

> var re = /.*?\\bb         


        
1条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-11 08:58

    /g (global) regexps will do that, yes.

    See this question.

    When you write a literal, you're getting a new regexp object every time, so losing the lastIndex state associated with the old object.

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