from string to raw string

Dan Perl danperl at rogers.com
Mon Dec 13 22:36:25 EST 2004


Is there a way to convert a regular string to a raw string so that one could 
get from '\bblah' to r'\bblah' other than parsing the string and modifying 
the escapes?

I am interested in this for the use of regular expressions.  I would like to 
be able to accept re patterns as inputs either from a file or from a GUI 
tool and I would like to allow those inputs as regular strings and not force 
users to write patterns with double escapes.

I naively thought there could be utilities for such a conversion either in 
the string module or the StringIO module but I don't see any utilities like 
that.

So, any suggestions?

Dan 





More information about the Python-list mailing list