Re:Python, Catastrophic Regular Expressions and the GIL (2013)
by matsemann on Monday November 14, 2022 @07:18AM
(#33592970)
Yeah, almost never what I want. Like if I have some "unstructured" data like
And I do a regex like /a="(.*)"/ I'd like it to match xxx, not until the end " after yyy. Always have to do weird tricks like /a="([^"]*)"/
[ Parent
| on HN ]
Re:Python, Catastrophic Regular Expressions and the GIL (2013)
by PenguinCoder on Monday November 14, 2022 @07:22AM
(#33592998)
Try `a="(.*?)\b"` next time. Where `\b` means a boundary such as the space in your example. Or use a more precise match for the capture group rather than the wildcard meaning ANYTHING.
Re:Python, Catastrophic Regular Expressions and the GIL (2013)
by Joker_vD on Monday November 14, 2022 @08:04AM
(#33593348)
Ah, the /"([^"]*)"/ trick. It was one of those small, obvious in retrospect but not that easy to invent on your own, useful things I was taught at my first job among others such as "if in a unit test you need a future date, use year 3001".