Using regexp method test in JS

Hello Campers,

I’m reading more about the regular expressions on javascript info and could you please confirm the following to me. There is a text:

That’s exactly because regexp.lastIndex is non-zero on the second test.
To work around that, one could use non-global regexps or re-adjust regexp.lastIndex=0 before a new search.

Link: (scroll to the very end, just before the summary)

Does it mean in order to get around the described issue the variable to which the regexp should be saved must be a local one but not a global, isn’t it?


yep, yes it is :innocent: