re module non-greedy matches broken

Fredrik Lundh fredrik at pythonware.com
Tue Apr 5 11:19:46 EDT 2005


"lothar" wrote:

> with respect to the documentation, the module is broken.

nope.

> the module does not necessarily deliver a "minimal length" match for a
> non-greedy pattern.

it isn't supposed to: a regular expression describes a *set* of matching
strings, and the engine is free to return any string from that set.  Python's
engine returns the *first* string it finds that belongs to the set.  if you use
a non-greedy operator, the engine will return the first non-greedy match
it finds, not the overall shortest non-greedy match.

if you don't want to understand how regular expressions work, don't use
them.

</F> 






More information about the Python-list mailing list