eliriclzj
eliriclzj

Reputation: 115

Clear invalid escape in python?

In Python, I have a string:

a = "\s"

In JavaScript, a would be the single letter "s", but in Python, a would be "\s".

How can I make Python behave the same way as JavaScript in this situation?


the real case may be more complicate : a = "<div class=\"haha\"><\/div>" , In this case , JavaScript get right HTML but python failed

Upvotes: 3

Views: 638

Answers (1)

jmunsch
jmunsch

Reputation: 24089

Assuming that there are no encoding/decoding that is happening?

Is a == r"\s" ?

You could simply:

a.replace('\\','')

example:

>>> a = "<div class=\"haha\"><\/div>"
>>> a.replace('\\','')
'<div class="haha"></div>'

See:

Upvotes: 1

Related Questions