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 50 times
0

jonrsharpe
- 115,751
- 26
- 228
- 437

pythad
- 4,241
- 2
- 19
- 41
-
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
- 172,303
- 28
- 230
- 274