regexp for sequence of quoted strings

Steven Bethard steven.bethard at gmail.com
Wed May 25 19:18:07 EDT 2005


Paul McGuire wrote:
>>>>text = r"'the','dog\'s','bite'"
>>>>def unquote(s,l,t):
> 
> ...     t2 = t[0][1:-1]
> ...     return t2.replace("\\'","'")
> ...

Note also, that the codec 'string-escape' can be used to do what's done 
with str.replace in this example:

py> s
"'the','dog\\'s','bite'"
py> s.replace("\\'", "'")
"'the','dog's','bite'"
py> s.decode('string-escape')
"'the','dog's','bite'"

Using str.decode() is a little more general as it will also decode other 
escaped characters.  This may be good or bad depending on your needs.

STeVe



More information about the Python-list mailing list