re.match -- not greedy?
Fredrik Lundh
fredrik at pythonware.com
Mon Nov 20 02:00:56 EST 2006
EXI-Andrews, Jack wrote:
>>>> import re;re.match('(a+)(ab)','aaab').groups()
> ('aa', 'ab')
>
> this is the sort of behaviour i'd expect from
> '(a+?)(ab)'
>
> a+ should greedily consume a's at the expense of the string
> not matching
that's a misunderstanding of what a regular expression is, though:
conceptually, a RE describes a set of strings, and the RE engine is
designed to answer the question "does this string belong to this
set".
</F>
More information about the Python-list
mailing list