Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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)
@pablofernandezorg

This comment has been minimized.

Copy link

@pablofernandezorg pablofernandezorg commented Dec 2, 2016

This does not work for all Emojis

@mpentler

This comment has been minimized.

Copy link

@mpentler mpentler commented Jan 26, 2018

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

This comment has been minimized.

Copy link

@mpentler mpentler commented Jan 26, 2018

Also what’s basestring?

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