3 ms·
The simple example is fixable by anchoring the inner greedy expression, i.e. regex = re.compile(r'(^a+)+b') Perhaps the more general problem was that "The reg
by photochemsyn 4y ago
The simple example is fixable by anchoring the inner greedy expression, i.e.
regex = re.compile(r'(^a+)+b')
Perhaps the more general problem was that "The regular expression that was causing the issue here was rather long and convoluted".
A good rule seems to be never have long and convoluted regexs, instead have a pipeline of simple-to-understand regexes that can be independently debugged (I don't know if this could cause performance slowdowns however).
- klyrs 4y agoWhy would you leave the second + intact, when the ^ prevents it from matching 2 or more times? And what if you want to match the substring in "Faaaaabulous"? Did you see the even simpler fix in TFA that doesn't break mid-string matches?
- photochemsyn 4y agoAh right I do now.