Reputation: 1
I'm trying to replace this unrecognized � text below here to a another text. What I did is decode it to UTF-8 and try to replace the unknown text below.
" you�"
varlistlabela = spss.GetVariableLabel(var)
varlistlabela=varlistlabela.decode("cp1252").replace(r'[\u0020-\ud7ff]',"").encode("cp1252")
Upvotes: 0
Views: 397
Reputation: 26039
You need a regex substitution:
re.sub(r'[^\u0020-\ud7ff]', '', s)
where s
is the input string.
Code:
import re
s = " you�"
print(re.sub(r'[^\u0020-\ud7ff]', '', s))
# you
Upvotes: 1