regex question

Helmut Jarausch jarausch at skynet.be
Mon Jun 9 16:59:34 EDT 2003


Eugene Yakubovich wrote:
> 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?
>  
Redoing your example in the current cvs version gives exactly what you
expect.

Python 2.3b1+ (#1, Jun  8 2003, 22:50:51)
[GCC 3.2.3] on linux2
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, None, 'abc')



-- 
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany





More information about the Python-list mailing list