John Machin <[EMAIL PROTECTED]> wrote: > What you want is: > >>> import re >>> text = r'frob this " avoid this \", OK?' >>>> text > 'frob this " avoid this \\", OK?' >>> re.sub(r'(?<!\\)"', r'\"', text) > frob this \\" avoid this \\", OK?' >>> >
Or you can do it without using regular expressions at all. Just replace them all and then fix up the result: >>> text = r'frob this " avoid this \", OK?' >>> text.replace('"', r'\"').replace(r'\\"', r'\"') 'frob this \\" avoid this \\", OK?' -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list