simulate backslash substitution identical to python parser

Fredrik Lundh fredrik at pythonware.com
Tue Apr 24 12:30:02 EDT 2001


Harald Kirsch wrote:
> 1) It is printed into a file which contains python code to be later
> executed.

file.write(repr(s))

> 2) It must be used immediately as a regexp.

assert re.match(re.escape(s), s) != None

(or in other words, re.escape(s) returns a pattern that matches
s if passed to the regular expression engine, for any possible s)

Cheers /F





More information about the Python-list mailing list