How to get the "longest possible" match with Python's RE module?
Licheng Fang
fanglicheng at gmail.com
Tue Sep 12 02:18:28 EDT 2006
Thank you very much, Tim and Monkee.
In fact, what I'm doing is handle a lot of regular expressions. I
wanted to build VERY LONG regexps part by part and put them all into a
file for easy modification and maintenance. The idea is like this:
(*INT) = \d+
(*DECIMAL) = (*INT)\.(*INT)
(*FACTION) = (*DECIMAL)/(*DECIMAL)
(*NUMERALS) = (*FACTION)|(*DECIMAL)|(*INT)
... ...
What's inside the sytactically wrong (* and ) is something to be
replaced, and then I wrote a little script to do the string
substitution, to get very long regexps to be compiled. I thought that
might be a way to handle long and complex regexps, and in this course I
encountered the problem with the semantics of '|'.
My approach may sound desperate and funny, but please, do you have any
good idea as to how to handle long and complex regexps?
More information about the Python-list
mailing list