Simple (I think) regex question

Michael Kelly jedimike at
Wed Nov 21 23:03:58 CET 2001

Hello all,

I've used Perl quite a bit, but am very new to Python, and am still getting
used to things. I'm not sure if I'm explaining this correctly or clearly,
but here goes:

My question is this: In a sub(), how do set the replacement string to be as
long as the first matched substring? (i.e., the len() of \1). I've tried
setting this as the replacement:

'*' * len(r'\1')

(the idea is to replace the matched string with *'s, no matter how long it

The above example, of course, replaces everything with "**", since the len()
of "\1" is 2.

Any help would be greatly appreciated.


-Michael Kelly
Email: jedimike at
The Web: 

More information about the Python-list mailing list