New Python regex Doc

Fredrik Lundh fredrik at pythonware.com
Mon May 9 08:00:57 EDT 2005


Mike Meyer wrote:

> After doing a google for "regular expression greedy", the second match
> starts with the text:
>
>      By default, pattern matching is greedy, which means that the matcher
>      returns the longest match possible.
>
> Now, it can be argued that the term ought not to be used, except that
> it's a standard term with a well-known meaning, and exactly describes
> the behavior in question.

fwiw, judging from frequently asked questions and bug reports,
people have no problems understanding the phrase "greedy", but
they sometimes have problems understanding why "return the
longest match possible" doesn't always mean "return the overall
longest match possible"

(using the greedy modifier only applies to the given RE operator;
it doesn't modify the behaviour of other operators, or the method
used; e.g. | will still pick the *first* possible match even if one of
the alternatives use a greedy operator, search/find still scans the
target string from left to right, etc).

</F>






More information about the Python-list mailing list