Point taken, thanks Aristotle. (MUDs don't ever use the semi-colon syntax, they just hang the sequences one after the other, thats my excuse anyway. ;)
C. | [reply] |
I'm confused by your use of (?> ... ) here, aristotle... any chance you could clear it up? (I did read the description in perlre; it didn't help clear things up).
Specificly, what does this pattern accomplish that s/\e\[\d+(;\d+)*m//g; doesn't?
Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).
| [reply] [d/l] |
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.
| [reply] |