leftmost longest match (of disjunctions) ; greediness of "|"
js at cis.uni-muenchen.de
Tue Dec 2 12:46:19 CET 2003
Joerg Schuster <js at cis.uni-muenchen.de> writes:
> Padraig at Linux.ie writes:
> > Joerg Schuster wrote:
> > > Peter Hansen <peter at engcorp.com> writes:
> > >
> > >> produce a longer overall match. In other words, the "|" operator
> > >> is never greedy.
> > > O.k. Thanks for pointing this out. Maybe I should have formulated my
> > > question differently: Is there a trick (be it dirty or not) to make
> > > "|" greedy in python?
> > sort the re by size first?
> The point is not to get the match of the longest part of the
> disjunction, but to get the match of that part of the disjunction
> which is the longest one. (The match of ".*" may be much longer than
> the match of "abc", although the latter regex contains more
I should have read your mail more carefully. You wrote about sorting
the *re*, not about sorting the regex. Sorry.
More information about the Python-list