Last active
August 29, 2015 14:21
-
-
Save talhasch/0bae3e2f5e57a4ff3035 to your computer and use it in GitHub Desktop.
python function that removes emojis from text
This file contains 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
def clean_emoji(text): | |
import re | |
try: | |
# Wide UCS-4 build | |
emoji_re = re.compile(u'[' | |
u'\U0001F300-\U0001F64F' | |
u'\U0001F680-\U0001F6FF' | |
u'\u2600-\u26FF\u2700-\u27BF]+', | |
re.UNICODE) | |
except re.error: | |
# Narrow UCS-2 build | |
emoji_re = re.compile(u'(' | |
u'\ud83c[\udf00-\udfff]|' | |
u'\ud83d[\udc00-\ude4f\ude80-\udeff]|' | |
u'[\u2600-\u26FF\u2700-\u27BF])+', | |
re.UNICODE) | |
text = emoji_re.sub(u'', text) | |
return text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment