Although there are similar questions, I can\'t seem to find a working solution for my case:
I\'m encountering some annoying hex chars in strings, e.g.
\'
You could make it check for valid letters, and instead of typing out everything, it's possible to use the string
module. The ones that may be useful to you are string.ascii_letters
(contains both string.ascii_lowercase
and string.ascii_uppercase
), string.digits
, string.printable
and string.punctuation
.
I'd try string.printable
first, but if it lets a few too many characters through, you could use a mix of the others.
Here's an example of how I'd do it:
import string
valid_characters = string.printable
start_string = '\xe2\x80\x9chttp://www.google.com\xe2\x80\x9d blah blah#%#@$^blah'
end_string = ''.join(i for i in start_string if i in valid_characters)