Created
October 22, 2015 07:40
-
-
Save jinstrive/34d1796bd2dd46b6aa52 to your computer and use it in GitHub Desktop.
python remove emoji in string
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
def remove_emoji(data): | |
""" | |
去除表情 | |
:param data: | |
:return: | |
""" | |
if not data: | |
return data | |
if not isinstance(data, basestring): | |
return data | |
try: | |
# UCS-4 | |
patt = re.compile(u'([\U00002600-\U000027BF])|([\U0001f300-\U0001f64F])|([\U0001f680-\U0001f6FF])') | |
except re.error: | |
# UCS-2 | |
patt = re.compile(u'([\u2600-\u27BF])|([\uD83C][\uDF00-\uDFFF])|([\uD83D][\uDC00-\uDE4F])|([\uD83D][\uDE80-\uDEFF])') | |
return patt.sub('', data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is this still not working for all emojis? I’d love to incorporate it into my project and it seems like a compact solution.