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
Mike Meyer wrote:
> "David Veerasingam" <[EMAIL PROTECTED]> writes:
[...]
> Of course, being the founder of SPARE, I have to point out that
> a.split(': ') will get you the same two strings as the re I used
> above.
>
Let me guess: the Society for the Prevention of Abuse of Regular
Expressions?
"David Veerasingam" <[EMAIL PROTECTED]> writes:
> 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 article <[EMAIL PROTECTED]>,
"David Veerasingam" <[EMAIL PROTECTED]> wrote:
> 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: '
>
>
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