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/mail

Re: Some more odd behaviour from the Regexp library

2005-10-20 Thread Steve Holden
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?

Re: Some more odd behaviour from the Regexp library

2005-10-19 Thread Mike Meyer
"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]: '' >

Re: Some more odd behaviour from the Regexp library

2005-10-19 Thread Doug Schwarz
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: ' > >

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.pytho