Storing/Retrieving python raw strings in a database

Laura Arbilla larbilla at clickfeed.com
Wed Aug 2 11:45:19 EDT 2000


This is what I'm doing:
User types a regular expression (in python raw string syntax)
in my html form, which is written in php:
http://www\.foo\.com

I store this reg exp in a mySQL database, the value in the database is:
http://www\\.foo\\.com
because single backslashes should be doubled when stored in mySQL.

Later, in a different process, I read the database value using python:
print `valueRead` prints:
'http://www\\\\.foo\\\\.com'
print valueRead prints:
http://www\\.foo\\.com

Now,I built an re object using the "valueRead":
re.compile(valueRead)
and now the following string doesn't match, when it should:
http://www.foo.com

I tried to replace the double backslashes with a single in valueRead,
but
this brakes in other cases where a back slash is used to scape double
quotes
in the database (\")

Can somebody help me here?
I really need a way to convert the contents of a python string variable
into
an equivalent  raw string that I can use as a regular expression.  I
searched
the FAQ and news groups and didn't find an answer.  Sorry if this
question
is duplicated.

I appreciate any help you can provide,
Laura.
larbilla at clickfeed.com







More information about the Python-list mailing list