Created
February 20, 2013 08:56
-
-
Save codeb2cc/4994086 to your computer and use it in GitHub Desktop.
Remove control characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unicodedata | |
import re | |
chars = (unichr(i) for i in xrange(0x110000)) | |
cc = ''.join(c for c in chars if unicodedata.category(c) == 'Cc') | |
# or equivalently and much more efficiently | |
cc = ''.join(map(unichr, range(0,32) + range(127,160))) | |
cc_re = re.compile('[%s]' % re.escape(cc)) | |
def remove_cc(s): | |
return cc_re.sub('', s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment