`re' difficulty?

Hrvoje Niksic hniksic at srce.hr
Tue Oct 19 15:45:30 EDT 1999


"Darrell" <darrell at dorb.com> writes:

> At the risk of showing my ignorance, this makes sense to me.
> [.0-9]+[a-z]? matched, so there was no need to find a match on the right
> hand side ???

Except that regular expressions are generally supposed to yield the
longest, not the first match.

I believe the current behaviour is an optimization -- if a match is
found in a subexpression, it is considered matched.  Otherwise, all
subexpressions would have to be matched in all cases merely to find
the longest match.  That operation might well be expensive.

FWIW, Perl behaves the same way.

The documentation doesn't seem to specify if the "greedy" behaviour of
regexps is supposed to apply to alternatives.




More information about the Python-list mailing list