[techtalk] Re: python re.sub help
Tessa Lau
tlau at cs.washington.edu
Wed Jan 26 15:11:16 EST 2000
Python was converting the \1 in your string to ASCII character code 001.
Try this:
re.sub('(%s)' % re.escape('http://127.0.0.1'), '\\1', var_a)
Alternatively you can use r'\1' instead of '\\1' (the r prefix means to
treat the following string as a raw string instead of processing backslash
escapes).
Don't forget to escape the regular expression pattern, since it contains
special characters such as dots that will match arbitrary characters in the
target string instead of literal periods.
--Tessa
************
techtalk at linuxchix.org http://www.linuxchix.org
More information about the Techtalk
mailing list