Skip to content

Instantly share code, notes, and snippets.

@onestarshang
Created June 1, 2017 07:49
Show Gist options
  • Select an option

  • Save onestarshang/0971cd03fd09b30682b81add4e5a5737 to your computer and use it in GitHub Desktop.

Select an option

Save onestarshang/0971cd03fd09b30682b81add4e5a5737 to your computer and use it in GitHub Desktop.
# coding=utf8
import re
def escape_emoji(txt):
try:
chars = re.compile(u'[\U00010000-\U0010ffff]')
except re.error:
chars = re.compile(u'[\uD800-\uDBFF][\uDC00-\uDFFF]')
return chars.sub(u'', txt).encode("utf-8")
def validate(raw_str):
try:
raw_str = raw_str.decode('unicode-escape').encode('latin1').decode('utf8')
new_str = escape_emoji(raw_str)
except:
raise
return new_str.encode('utf8')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment