re module non-greedy matches broken

André Malo auch-ich-m at g-kein-spam.com
Sun Apr 3 12:17:55 EDT 2005


* lothar wrote:

> re:
> 4.2.1 Regular Expression Syntax
> http://docs.python.org/lib/re-syntax.html
> 
>   *?, +?, ??
>   Adding "?" after the qualifier makes it perform the match in non-greedy
>   or
> minimal fashion; as few characters as possible will be matched.
> 
> the regular expression module fails to perform non-greedy matches as
> described in the documentation: more than "as few characters as possible"
> are matched.
> 
> this is a bug and it needs to be fixed.

The documentation is just incomplete. Non-greedy regexps still start
matching the leftmost. So instead the longest of the leftmost you get the
shortest of the leftmost. One may consider this as a documentation bug,
yes.

nd
-- 
# André Malo, <http://www.perlig.de/> #



More information about the Python-list mailing list