I found this on the web...
Calling the exec() function also changes the lastIndex
property of the RegExp object.
It stores the index in the subject string at which the next match attempt will begin.
You can modify this value to change the starting position of the
next call to exec().
The behavior you describe indicates that the RegExp
object has a state that is modified by calling the exec() method.
I think you need to modify the lastindex
property before you re-run the exec method.
read more here: Javascript Regexp Object