re.sub replacement text \-escapes woe

David M. Wilson dw-google.com at botanicus.net
Fri Feb 13 19:35:53 EST 2004


Alexander Schmolck wrote:
> Sorry if I missed something obvious, but how do you do this more
> intelligently?
> 
> def escape(s):
>     return re.sub(r'([${}\\])', r'\ \1', s).replace('\\ ', '\\')
> 

re.escape? :)


David




More information about the Python-list mailing list