0

How to replace '\\\\' with '\\' in Python? For example: "Shady \\\ vs \\\ everybody" -----> "Shady \ vs \ everybody". I tried r"", and \\ but it does not work...

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
pythad
  • 4,241
  • 2
  • 19
  • 41

1 Answers1

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