How to get the "longest possible" match with Python's RE module?
gatti at dsdata.it
gatti at dsdata.it
Wed Sep 13 03:35:16 EDT 2006
Frederic Rentsch wrote:
> If you need regexes, why not just reverse-sort your expressions? This
> seems a lot easier and faster than writing another regex compiler.
> Reverse-sorting places the longer ones ahead of the shorter ones.
Unfortunately, not all regular expressions have a fixed match length.
Which is the longest of, for example, /(abc)?def/ and /(def)?ghi/
depends on the input.
Lorenzo Gatti
More information about the Python-list
mailing list