Author tim.peters
Recipients kleshni, tim.peters
Date 2020-05-04.00:00:38
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
"The trick" with this kind of pattern is that a `*` should consume as little as possible to allow the next fixed portion to match.  Apply that at every stage, and it succeeds or it doesn't.  Backtracking can't change that outcome.  For, e.g., the shell pattern:


a regexp to do this without backtracking would be like this, IF Python's re engine supported "atomic groups" (but it doesn't):


The same effect can be gotten in a more convoluted way, via positive lookahead assertions and backreferencing (which Python's re engine does support):


Assertions are "one and done":  if the overall match fails, assertions don't try alternatives.

So that's _a_ way to proceed.  I'm unclear on that it's worth it, though.  Stuff like "*a*a*a*a*a*a*" is just hard to swallow as a shell pattern that would occur in real life.
Date User Action Args
2020-05-04 00:00:38tim.peterssetrecipients: + tim.peters, kleshni
2020-05-04 00:00:38tim.peterssetmessageid: <>
2020-05-04 00:00:38tim.peterslinkissue40480 messages
2020-05-04 00:00:38tim.peterscreate