That’s exactly because
regexp.lastIndexis non-zero on the second test.
To work around that, one could use non-global regexps or re-adjust
regexp.lastIndex=0before a new search.
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?