Simple (I think) regex question

Michael Kelly jedimike at mac.com
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
is)

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

Any help would be greatly appreciated.

Thanks!


-Michael Kelly
Email: jedimike at mac.com
The Web: http://www.jedimike.net 




More information about the Python-list mailing list