re module non-greedy matches broken

lothar lothar at ultimathule.nul
Tue Apr 5 12:24:05 EDT 2005


a non-greedy match is implicitly defined in the documentation to be one such
that there is no proper substring in the return which could also match the
regex.

the documentation implies the module will return a non-greedy match.

the module does not return a non-greedy match.


"Fredrik Lundh" <fredrik at pythonware.com> wrote in message
news:mailman.1392.1112714523.1799.python-list at python.org...
> "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