How to replace '\\\\' with '\\' in Python?
For example: "Shady \\\ vs \\\ everybody" -----> "Shady \ vs \ everybody".
I tried r"", and \\ but it does not work...
Asked
Active
Viewed 47 times
0
jonrsharpe
- 107,083
- 22
- 201
- 376
pythad
- 4,115
- 2
- 15
- 40
-
I should take my string as an input. – pythad Feb 03 '15 at 12:00
1 Answers
0
Use double backslash to match a single backslash character.
>>> s = r'Shady \\\ vs \\\ everybody'
>>> print(s.replace('\\\\\\', '\\'))
Shady \ vs \ everybody
Avinash Raj
- 166,785
- 24
- 204
- 249