As my comment said, I guess the "\u0026" is an escaped string.
That is, the real input should be something like
a = "\\u0026"
with double backslashes to enter a real "\".
Then, we may use json.loads
as a tricky reverse function for re.escape
, for example:
import json
json.loads("{\"downloadFile\":\"/myportal/ABC/35/audio/182/audio?Id=996\\u0026stepNo=0\\u0026resource=996-0-dde82d48-3097-4835-a1e4-30602c460fd7-1.wav\"}")
# output:
# {'downloadFile': '/myportal/ABC/35/audio/182/audio?Id=996&stepNo=0&resource=996-0-dde82d48-3097-4835-a1e4-30602c460fd7-1.wav'}
Or wrap it into a function:
def deescape(escaped):
return str(json.loads("{\"s\":\"" + escaped + "\"}"))[7 : -2]
deescape("\\u0026") # return '&'
Update: This solution is not suitable if escaped
contains ":". The real solution should be:
# Python 2
def deescape(escaped)
return escaped.decode('string_escape')
# Python 3
def deescape(escaped)
return escaped.encode().decode('unicode_escape')