Skip to content

Instantly share code, notes, and snippets.

@jezdez
Created December 7, 2015 19:36
Show Gist options
  • Save jezdez/0185e35704dbdf3c880f to your computer and use it in GitHub Desktop.
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
# -*- 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'))
@Kevinpgalligan
Copy link

This should get you a list of all the emojis in the text:

[c for c in string if char_is_emoji(c)]

@bertdida
Copy link

bertdida commented Apr 15, 2019

Below works fine for me;

has_emoji = bool(emoji.get_emoji_regexp().search(text))

Copy link

ghost commented Jul 20, 2020

Your Code was very helpfull, thanks a lot !

@z4id
Copy link

z4id commented May 13, 2022

@bertdida +1 for simple and fast solution.

@hypy13
Copy link

hypy13 commented May 23, 2022

@bertdida working well thanks 👍 👍 👍

@claram97
Copy link

claram97 commented Apr 4, 2023

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.

@danner26
Copy link

@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