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
esca
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
balterdash! let me rephrase:
re.sub("(http://127.0.0.1)", 1, var_a)
how do i store the "(http://127.0.0.1)" part and reuse it in the
replacement variable?
On Wed, 26 Jan 2000, Tessa Lau wrote:
>
> This appears to work for me (Python 1.5.2):
> >>> var_a = "http://127.0.0.1/email/logout"
> >>> v
This appears to work for me (Python 1.5.2):
>>> var_a = "http://127.0.0.1/email/logout"
>>> var_b = "http://www.lazygirl.com"
>>> var_a = re.sub("http://127.0.0.1", var_b, var_a)
>>> var_a
'http://www.lazygirl.com/email/logout'
What do you think is wrong?
> var_a = re.sub("http://127.0.0.1", "%