Home > Back-end >  how to remove a backslash from a python string
how to remove a backslash from a python string

Time:02-17

I know this seems like a duplicate question but unsure why this string seems to not want to ditch its backslash.

I am using python 3.8

example String

'"sourceSystem" : \'somethingsomething",' 

Code I have tried

>>> word = '"sourceSystem" : \'somethingsomething",'
>>> word.strip()
>>> word.replace('\\', '')
>>> word.split('\\')
>>> re.sub(r"\\.*", "", word)

Any suggestions?

CodePudding user response:

    word='"sourceSystem" : \'somethingsomething",'

    string = word.replace("\\","")

    print(string)


    output : "sourceSystem" : 'somethingsomething",

CodePudding user response:

s ='"sourceSystem" : \'somethingsomething",'
s1 = s.translate({ord('\\'): None})
print(s1)

output
"sourceSystem" : 'somethingsomething",
  • Related