regexp substitution - a lot of work!

Duncan Booth me at
Thu Jun 17 10:44:37 CEST 2004

Lukas Holcik <xholcik1 at> wrote in
news:Pine.LNX.4.60.0406161824510.15043 at 

> Yes, sorry, I was in such a hurry I didn't found it in the
> documentation, but when I want to use a lot of very different
> expressions using a lot of different grouping, which would be easy to
> implement using s/(..)/x\1x/ then it is quite problematic having to
> use re.sub(), isn't it? 

I don't understand your point. The Python equivalent is:

   re.sub('(..)', r'x\1x', s)

or using a precompiled pattern:

  pat.sub(r'x\1x', s)

More information about the Python-list mailing list