regex question

Mike Rovner mike at bindkey.com
Mon Jun 9 16:02:57 EDT 2003


You can get (None, None, 'abc') if you use non-greedy re: r'((a)5)*?(abc)',
'abc'.
Also re.match(r'(aaaaa)*(abc)', 'abc').groups() gives you: (None, 'abc')

My guess is that in case of nested groups you get backtracking of outer
group
which doesn't reset inner group match.

Just 0.02

Mike


"Eugene Yakubovich" <eyakubovich at cccglobal.com> wrote in message
news:003901c32ebe$cf30c650$9c01090a at 4test...
Hello,

I have a question about regular expression matching.  Consider the
following:

Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.8 -- press F1 for help
>>> import re
>>> re.match(r'((a)5)*(abc)', 'abc').groups()
(None, 'a', 'abc')
>>>

I would think that I would get (None, None, 'abc') since ((a)5)* would not
match even once.
Can anyone explain how regular expression engine matches this expression?

Thank you,
Eugene
eyakubovich at cccglobal.com








More information about the Python-list mailing list