re.match -- not greedy?
EXI-Andrews, Jack
Jack.Andrews at boeing.com
Wed Nov 22 01:18:13 EST 2006
>> I 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
>
> Fredrick wrote:
> 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".
if that's so, what is the point of +? and *? (?)
seems to me it's a bit more pragmatic than pure set membership
jack
More information about the Python-list
mailing list