Making the substitution string raw in re.sub()
Joakim Hove
hove at phys.ntnu.no
Tue Oct 31 15:37:33 EST 2000
Hello,
I'm using the re module to perform some substitutions on a string:
OldString = "See for instance EXPAND(key1)"
newString = r"Volume {\bf 45}"
print re.sub(r"EXPAND\(\s*(\w+?)\s*\)" , newString , OldString , 1)
But, when I run this the newString is not properly escaped, and
what I get is:
>>> See for instance Volume f 45}
instead of:
>>> See for instance Volume {\bf 45}
Which is what I wanted. ANy tips to how I Could solve this??
Regards - Joakim
--
=== Joakim Hove www.phys.ntnu.no/~hove/ ======================
# Institutt for fysikk (735) 93637 / E3-166 | Skøyensgate 10D #
# N - 7491 Trondheim hove at phys.ntnu.no | N - 7030 Trondheim #
================================================ 73 93 31 68 ========
More information about the Python-list
mailing list