1// A JavaScript RegExp object is stateful.
2// When the regex is global, if you call a method on the same regex object, it will start from the index past the end of the last match.
3// When no more matches are found, the index is reset to 0 automatically.
4
5reg.lastIndex = 0;