[newbie] Strange behavior of the re module

Fred fred at acme.com
Sat Aug 21 17:10:09 CEST 2004

On Sat, 21 Aug 2004 14:50:40 +0200, Fred <fred at acme.com> wrote:
>That did it :-) Thx a bunch.

Mmmm... The above links and hints did teach more about the infamous
"blackslash plague", but I'm still stuck because all the examples
consider static strings, while I'm building it dynamically by
extracting data from a web page through the re module:

import sys
import re

#1. Extract stuff between BODY tags
input = "<body>c:\temp</body>"
body = re.search('<body.*?>(.*?)</body>',input,re.IGNORECASE |
if body:
	body = body.group(1)
print "Body = " + body

#2. Insert extracted stuff into template
output = "<body>here's the path: </body>"
output = re.sub('</body>', body + "</body>", output)
print output

I also tried running this before so that the problem would go away,
but Python doesn't like it either:

body = re.sub(r'\',r'\\',input)

The script does run, but 

More information about the Python-list mailing list