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
  • 107,083
  • 22
  • 201
  • 376
pythad
  • 4,115
  • 2
  • 15
  • 40

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
  • 166,785
  • 24
  • 204
  • 249