Some more odd behaviour from the Regexp library

2005-10-19 Thread David Veerasingam
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.python.org/mailman/listinfo/python-list


Re: Some more odd behaviour from the Regexp library

2005-10-20 Thread David Veerasingam
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/mailman/listinfo/python-list


Odd behaviour of regexp module

2005-07-13 Thread David Veerasingam
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