re module non-greedy matches broken

Fredrik Lundh fredrik at pythonware.com
Tue Apr 5 13:40:54 EDT 2005


"lothar" wrote:

>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.

no, that's not what it says.  this is what is says:

    Adding "?" after the qualifier makes it perform the match in non-greedy
    or minimal fashion; as few characters as possible will be matched.

note that it says "qualifier" (that is, the preceeding *, +, or ? operator). it
doesn't say that the *entire* regex should be non-greedy.  it does not say
that search, findall, sub etc. should look for the shortest possible overall
match.  all it says is that the preceeding operator, and that operator only,
should look for the shortest possible match, rather than the longest.

> the module does not return a non-greedy match.

it does.  the problem is all in your head.

</F> 






More information about the Python-list mailing list