Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
remove emoji in python
#!/usr/bin/env python
# coding: utf-8
import re
text = u'This dog \U0001f602'
print(text) # with emoji
def remove_emoji(data):
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:
print "we got not wide python"
# UCS-2
patt = re.compile(u'([\u2600-\u27BF])|([\uD83C][\uDF00-\uDFFF])|([\uD83D][\uDC00-\uDE4F])|([\uD83D][\uDE80-\uDEFF])')
return patt.sub('', data)
print(remove_emoji(text)) # no emoji
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.