Re: Non greedy regex

2006-12-14 Thread Maksim Kasimov
> print re.sub( 'a.*?b', '', 'ababc' ) > > gives: 'c' you've forgot "^" at the begging of the pattern (there is another 'ab' before 'c') print re.sub( '^a.*?b', '', 'ababc' ) [EMAIL PROTECTED] wrote: > Can someone please explain why these expressions both produce the same > result? Surel

Re: Non greedy regex

2006-12-14 Thread Thomas Nelson
There's an optional count argument that will give what you want. Try re.sub('a.*b','','ababc',count=1) Carsten Haese wrote: > On Thu, 2006-12-14 at 06:45 -0800, [EMAIL PROTECTED] wrote: > > Can someone please explain why these expressions both produce the same > > result? Surely this means that

Re: Non greedy regex

2006-12-14 Thread Carsten Haese
On Thu, 2006-12-14 at 06:45 -0800, [EMAIL PROTECTED] wrote: > Can someone please explain why these expressions both produce the same > result? Surely this means that non-greedy regex does not work? > > print re.sub( 'a.*b', '', 'ababc' ) > > gives: 'c' > > Understandable. But > > print re.sub(