I just noticed the following strange behavior (both in browsers and nodejs:
> a = /^\/foo/g
/^\/foo/g
> a.test("/foo")
true
> a.test("/foo")
false
> a.test("/foo")
true
> a.test("/foo")
false
> a.test("/foo")
true
What kind of mad science we have here? How can I prevent this behavior?
I just want to have a regex variable that checks if a string matches the pattern globally.
Documentation pages don't seem to bring some light there... I'd really appreciate a link to documentation references.