in reply to Re: Re: Removing ANSI Color Codes
in thread Removing ANSI Color Codes

Nothing, in this case. *g* It will just fail a notch faster in cases where it can't match.

The reason is that once the (;\d+)* stops, if what follows isn't an m, the regex engine will backtrack, giving up a bit of what (;\d+)* matched, trying to find an m. Of course we know that neither the semicolon nor \d can match something that is an m, so no backtracking in the world is going to help and make it match.

What (?>re) does is throw away all the intermediate states once re has matched, so if backtracking seems necessary, the engine will not remember how to backtrack into the middle of re. Effectively, if the engine fails to find an m after the (?>re), it will unmatch re all at once, rather than waste time doing so character by character.

Makeshifts last the longest.

  • Comment on Re^3: Removing ANSI Color Codes (atomic grouping)