why does my javascript regex.test() give alternating results [duplicate]

When you’re using /g, the regex object will save state between calls (since you should be using it to match over multiple calls). It matches once, but subsequent calls start from after the original match.

(This is a duplicate of Javascript regex returning true.. then false.. then true.. etc)

Leave a Comment