Your regex is searching for next match. The index where it stopped is stored in urlRegExp.lastIndex
Because there's a g flag.
So it will store lastIndex and wait for the next test.
JavaScript RegExp objects are stateful when they have the global or sticky flags set (e.g., /foo/g or /foo/y). They store a lastIndex from the previous match.