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. <snip> > > In first sub I expected, > one two - one two > > I understand that \1 is first (group), \2 the second and etc. > But what is the entire regex?
>>> re.sub('(one) (two)', r'\g<0> - \1 \2',s) the \g<number> 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. _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor