Thanks for all your replies.
I guess I've always used .*? as sort of an idiom for a non-greedy
match, but I guess it only works if I specify the end point (which I
didn't in the above case).
e.g. re.search(r'exit: (.*?)$', a)
Thanks for pointing that out!
David
--
http://mail.python.org/mail
Can anyone explain why it won't give me my captured group?
In [1]: a = 'exit: gkdfjgfjdfsgdjglkghdfgkd'
In [2]: import re
In [3]: b = re.search(r'exit: (.*?)', a)
In [4]: b.group(0)
Out[4]: 'exit: '
In [5]: b.group(1)
Out[5]: ''
In [6]: b.group(2)
IndexError: no such group
--
http://mail.pytho
Hello
It seems the grouping feature isn't behaving correctly.
In [1]: a = 'dfsf.oct.ocfe'
In [2]: b = re.match(r'^(.*?)\.', a); b.group()
'dfsf.'
The expected result is 'dfsf'. Why did the regexp grab that period at
the end?
David
--
http://mail.python.org/mailman/listinfo/python-list