Re: Something confusing about non-greedy reg exp match

2009-09-07 Thread Duncan Booth
"gburde...@gmail.com" wrote: > If I do this: > > import re > a=re.search(r'hello.*?money', 'hello how are you hello funny money') > > I would expect a.group(0) to be "hello funny money", since .*? is a > non-greedy match. But instead, I get the whole sentence, "hello how > are you hello funny

Re: Something confusing about non-greedy reg exp match

2009-09-07 Thread Paul McGuire
On Sep 6, 11:23 pm, Ben Finney wrote: > George Burdell writes: > > I want to find every occurrence of "money," and for each > > occurrence, I want to scan back to the first occurrence > > of "hello." How can this be done? > > By recognising the task: not expression matching, but lexing and > pars

Re: Something confusing about non-greedy reg exp match

2009-09-07 Thread MRAB
George Burdell wrote: On Sep 6, 10:06 pm, "Mark Tolonen" wrote: wrote in message news:f98a6057-c35f-4843-9efb-7f36b05b6...@g19g2000yqo.googlegroups.com... If I do this: import re a=re.search(r'hello.*?money', 'hello how are you hello funny money') I would expect a.group(0) to be "hello fun

Re: Something confusing about non-greedy reg exp match

2009-09-07 Thread 7stud
On Sep 6, 8:46 pm, "gburde...@gmail.com" wrote: > If I do this: > > import re > a=re.search(r'hello.*?money',  'hello how are you hello funny money') > > I would expect a.group(0) to be "hello funny money", since .*? is a > non-greedy match. But instead, I get the whole sentence, "hello how > are

Re: Something confusing about non-greedy reg exp match

2009-09-06 Thread Ben Finney
George Burdell writes: > I want to find every occurrence of "money," and for each occurrence, I > want to scan back to the first occurrence of "hello." How can this be > done? By recognising the task: not expression matching, but lexing and parsing. For which you might find the ‘pyparsing’ libra

Re: Something confusing about non-greedy reg exp match

2009-09-06 Thread Gary Herron
George Burdell wrote: On Sep 6, 10:06 pm, "Mark Tolonen" wrote: wrote in message news:f98a6057-c35f-4843-9efb-7f36b05b6...@g19g2000yqo.googlegroups.com... If I do this: import re a=re.search(r'hello.*?money', 'hello how are you hello funny money') I would expect a.gr

Re: Something confusing about non-greedy reg exp match

2009-09-06 Thread George Burdell
On Sep 6, 10:06 pm, "Mark Tolonen" wrote: > wrote in message > > news:f98a6057-c35f-4843-9efb-7f36b05b6...@g19g2000yqo.googlegroups.com... > > > If I do this: > > > import re > > a=re.search(r'hello.*?money',  'hello how are you hello funny money') > > > I would expect a.group(0) to be "hello fun

Re: Something confusing about non-greedy reg exp match

2009-09-06 Thread George Burdell
On Sep 6, 10:22 pm, George Burdell wrote: > On Sep 6, 10:06 pm, "Mark Tolonen" wrote: > > > > > > > wrote in message > > >news:f98a6057-c35f-4843-9efb-7f36b05b6...@g19g2000yqo.googlegroups.com... > > > > If I do this: > > > > import re > > > a=re.search(r'hello.*?money',  'hello how are you hell

Re: Something confusing about non-greedy reg exp match

2009-09-06 Thread George Burdell
On Sep 6, 10:06 pm, "Mark Tolonen" wrote: > wrote in message > > news:f98a6057-c35f-4843-9efb-7f36b05b6...@g19g2000yqo.googlegroups.com... > > > If I do this: > > > import re > > a=re.search(r'hello.*?money',  'hello how are you hello funny money') > > > I would expect a.group(0) to be "hello fun

Re: Something confusing about non-greedy reg exp match

2009-09-06 Thread r
EDIT: your regex matches the whole string because it means... "hello" followed by any number of *anythings* up to the first occurrence of "money") you see? -- http://mail.python.org/mailman/listinfo/python-list

Re: Something confusing about non-greedy reg exp match

2009-09-06 Thread Mark Tolonen
wrote in message news:f98a6057-c35f-4843-9efb-7f36b05b6...@g19g2000yqo.googlegroups.com... If I do this: import re a=re.search(r'hello.*?money', 'hello how are you hello funny money') I would expect a.group(0) to be "hello funny money", since .*? is a non-greedy match. But instead, I get th

Re: Something confusing about non-greedy reg exp match

2009-09-06 Thread r
On Sep 6, 9:46 pm, "gburde...@gmail.com" wrote: > If I do this: > > import re > a=re.search(r'hello.*?money',  'hello how are you hello funny money') > > I would expect a.group(0) to be "hello funny money", since .*? is a > non-greedy match. But instead, I get the whole sentence, "hello how > are

Something confusing about non-greedy reg exp match

2009-09-06 Thread gburde...@gmail.com
If I do this: import re a=re.search(r'hello.*?money', 'hello how are you hello funny money') I would expect a.group(0) to be "hello funny money", since .*? is a non-greedy match. But instead, I get the whole sentence, "hello how are you hello funny money". Is this expected behavior? How can I s