Why is RegExp.test() not consistent?

后端 未结 1 988
既然无缘
既然无缘 2020-12-20 00:08

I do not understand why the javascript RegExp.test() method do no return the same result every time I call it.

Given the following javascript variables<

相关标签:
1条回答
  • 2020-12-20 00:12

    That's because you use the g flag. It turns the regexp object into an iterator, whose state changes with each call.

    You don't need the g flag here, so just remove it :

    var regexo = new RegExp('^'+opener+'$');
    
    0 讨论(0)
提交回复
热议问题