Skip to content

Instantly share code, notes, and snippets.

@gaotongfei
Created August 18, 2016 19:36
Show Gist options
  • Save gaotongfei/53185817ad5d92b11ab849c19313bb47 to your computer and use it in GitHub Desktop.
Save gaotongfei/53185817ad5d92b11ab849c19313bb47 to your computer and use it in GitHub Desktop.
import string
s = "Miljkovi´c, K¨all"
printable = set(string.printable)
print(filter(lambda x: x in printable, s))
<!--more-->
结果:
`
Miljkovic, Kall
`
或者用正则表达式:
{% highlight python %}
import re
s = "Miljkovi´c, K¨all"
print(re.sub(r'[^\x00-\x7f]', r'', s))
{% endhighlight %}
参考自[stackoverflow](http://stackoverflow.com/questions/8689795/how-can-i-remove-non-ascii-characters-but-leave-periods-and-spaces-using-python/8689826#8689826)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment