Does anyone know how replace all
\\ in python?
But it screws it up because of the escape sequence. does anyone know the awnser to my question?
You just need to escape the backslashes in your strings: (also there's no need for regex stuff)
>>> s = "cats \\ dogs" >>> print s cats \ dogs >>> print s.replace("\\", "\\\\") cats \\ dogs
you should do:
re.sub(r'\\', r'\\\\', string)
r'\' is not a valid string
BTW, you should always use raw (
r'') strings with regex as many things are done with backslashes.