News for hackers. Stuff that matters.
Re:Python, Catastrophic Regular Expressions and the GIL (2013) by photochemsyn on Monday November 14, 2022 @09:40AM (#33594548)
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).

Re:Python, Catastrophic Regular Expressions and the GIL (2013) by klyrs on Monday November 14, 2022 @10:47AM (#33595691)
Why 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?

Re:Python, Catastrophic Regular Expressions and the GIL (2013) by photochemsyn on Monday November 14, 2022 @11:01AM (#33595973)
Ah right I do now.