Created
December 7, 2015 19:36
-
-
Save jezdez/0185e35704dbdf3c880f to your computer and use it in GitHub Desktop.
A Python script to check if a character is or a text contains 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
# -*- encoding: utf-8 -*- | |
# pip install emoji | |
import emoji | |
def char_is_emoji(character): | |
return character in emoji.UNICODE_EMOJI | |
def text_has_emoji(text): | |
for character in text: | |
if character in emoji.UNICODE_EMOJI: | |
return True | |
return False | |
if __name__ == '__main__': | |
print(char_is_emoji(u'\u2764')) | |
print(text_has_emoji(u'I \u2764 emoji')) |
This should get you a list of all the emojis in the text:
[c for c in string if char_is_emoji(c)]
Below works fine for me;
has_emoji = bool(emoji.get_emoji_regexp().search(text))
Your Code was very helpfull, thanks a lot !
@bertdida +1 for simple and fast solution.
@bertdida working well thanks 👍 👍 👍
I got an error using "UNICODE_EMOJI", i fixed it using "EMOJI_DATA" instead :)
It seems like the property UNICODE_EMOJI was removed in version 2.0.0 of emoji module.
@claram97 thank you, EMOJI_DATA
is the proper replacement for UNICODE_EMOJI
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hey, plz tell me how can i find emoji from text tell me the whole process i have no idea about python i m the beginner to python