Last active
May 22, 2020 01:56
-
-
Save shinkou/be69c1478f8a6989294aaca143d85b47 to your computer and use it in GitHub Desktop.
A Python 3 snippet which detects if input parameters have any emoji
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
#!/usr/bin/env python3 | |
# vim: fenc=utf-8 ff=unix lcs=tab\:>. list noet ru sw=4 ts=4 tw=0 | |
# | |
# How to use: | |
# $ emoji_detector.py 'sentence with emoji <INSERT EMOJI HERE>' ... | |
# | |
import re, sys | |
# [\u00a9\u00ae\u203c-\u2b55\u3030\u303d\u3297\u3299\U0001f004-\U0001fad6] # Emoji | |
# [\U0001f3fb-\U0001f3ff] # EMod | |
# [\U0001f1e6-\U0001f1ff] # RI | |
# [\U000e0020-\U000e007e]+\U000e007f # TagMod | |
# [\u0023\u002a\u0030-\u0039] # Digits | |
REGEXP_EMOJI = r''' | |
[\U0001f1e6-\U0001f1ff]{2} | |
|[\u0023\u002a\u0030-\u0039]\ufe0f?\u20e3 | |
|[\u00a9\u00ae\u203c-\u2b55\u3030\u303d\u3297\u3299\U0001f004-\U0001fad6] | |
(?:[\U0001f3fb-\U0001f3ff] | |
|\ufe0f\u20e3? | |
|[\U000e0020-\U000e007e]+\U000e007f)? | |
(?:\u200d[\u00a9\u00ae\u203c-\u2b55\u3030\u303d\u3297\u3299\U0001f004-\U0001fad6] | |
(?:[\U0001f3fb-\U0001f3ff] | |
|\ufe0f\u20e3? | |
|[\U000e0020-\U000e007e]+\U000e007f)? | |
)* | |
''' | |
def emoji(s): | |
if re_emoji.search(s) is not None: | |
ms = re_emoji.findall(s) | |
for m in ms: | |
print(m) | |
print() | |
if '__main__' == __name__: | |
global re_emoji | |
re_emoji = re.compile(REGEXP_EMOJI, re.X) | |
for arg in sys.argv[1:]: | |
emoji(arg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment