Re: [Tutor] backreferences - \0

2010-06-06 Thread Payal
On Sun, Jun 06, 2010 at 07:52:43PM +1000, Lie Ryan wrote: > >>> re.sub('(one) (two)', r'\g<0> - \1 \2',s) > > the \g is equivalent to \number but is intended to ambiguate > cases like "\g<2>0" vs. "\20". It happens that \g<0> refers to the > entire group. Thanks a lot. It works as you say. With

Re: [Tutor] backreferences - \0

2010-06-06 Thread Lie Ryan
On 06/06/10 19:36, Payal wrote: > On Sun, Jun 06, 2010 at 06:26:18PM +1000, Steven D'Aprano wrote: >> Two things. Firstly, the Python regex engine numbers backreferences from >> 1, not 0, so you need \1 and not \0. > > Thank for the mail, but i am still not getting it. e.g. > > In first sub I e

Re: [Tutor] backreferences - \0

2010-06-06 Thread Payal
On Sun, Jun 06, 2010 at 06:26:18PM +1000, Steven D'Aprano wrote: > Two things. Firstly, the Python regex engine numbers backreferences from > 1, not 0, so you need \1 and not \0. Thank for the mail, but i am still not getting it. e.g. >>> import re >>> s = 'one two' >>> re.sub('(one) (two)', r'

Re: [Tutor] backreferences - \0

2010-06-06 Thread Steven D'Aprano
On Sun, 6 Jun 2010 05:32:26 pm Payal wrote: > Hi, > A newbie re query. > > >>> import re > >>> s='one' > >>> re.sub('(one)','only \\0',s) > > 'only \x00' > > >>> re.sub('(one)','only \0',s) > > 'only \x00' > > I expected the output to be 'only one' with \0 behaving like "&" in > sed. What is wrong

[Tutor] backreferences - \0

2010-06-06 Thread Payal
Hi, A newbie re query. >>> import re >>> s='one' >>> re.sub('(one)','only \\0',s) 'only \x00' >>> re.sub('(one)','only \0',s) 'only \x00' I expected the output to be 'only one' with \0 behaving like "&" in sed. What is wrong with my syntax? With warm regards, -Payal -- _