python - Removing escape characters from a string -


how can remove escape chars in python 2.7 , python 3 ?

example:

a = "\u00e7a\u00e7a\u00e7a=http\://\u00e1\u00e9\u00ed\u00f3\u00fa\u00e7/()\=)(){[]}" decoded =  a.decode('unicode_escape') print decoded 

result:

çaçaça=http\://áéíóúç/()\=)(){[]} 

expected result

çaçaça=http://áéíóúç/()=)(){[]} 

edit: in order avoid unnecessary downvotes. using .replace isn't our primary focus since problem raised legacy solution other teams ( db table reference data contains portuguese chars , regular expressions).

you're looking simple str.replace

>>> print decoded.replace('\\', '') çaçaça=http://áéíóúç/()=)(){[]} 

the remaining \ literal backslash, not escape sequence.


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -