[techtalk] Re: python re.sub help

Tricia Bowen bowen at starmedia.net
Wed Jan 26 18:18:46 EST 2000


thanks tessa. that worked like a charm. i also got \g<1> to work.

On Wed, 26 Jan 2000, Tessa Lau wrote:

> 
> 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
> 

-tricia

#-----------
Tricia Bowen
Applications Engineer
Starmedia Network
v: 212.520.6469
m: 917.578.3425



************
techtalk at linuxchix.org   http://www.linuxchix.org




More information about the Techtalk mailing list