-
-
Save habedi/656052586d2da10007368f6e7989a48b to your computer and use it in GitHub Desktop.
python remove emoji in string
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 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