Surprisingly this is not a bug, though I was certain it was at first. When using the global flag the RegExp object will keep track of the last matching character position and start the next comparison at that position (after the 4th character, in this case) which results in this seemingly incorrect alternation between "asdf" matching "asdf". Removing the global flag produces correct results.