Skip to content

Instantly share code, notes, and snippets.

@jinstrive
Created October 22, 2015 07:40
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jinstrive/34d1796bd2dd46b6aa52 to your computer and use it in GitHub Desktop.
Save jinstrive/34d1796bd2dd46b6aa52 to your computer and use it in GitHub Desktop.
python remove emoji in string
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)
@mpentler
Copy link

Is this still not working for all emojis? I’d love to incorporate it into my project and it seems like a compact solution.

@mpentler
Copy link

Also what’s basestring?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment