I want to check that a string contains only one emoji, using Python 3.
For example, there is a is_emoji
function that checks that the string has only one emoji.
def is_emoji(s):
pass
is_emoji("π") #True
is_emoji("πβΌοΈ") #False
I try to use regular expressions but emojis didn't have fixed length. For example:
print(len("βΌοΈ".encode("utf-8"))) # 6
print(len("π".encode("utf-8"))) # 4
"βΌοΈ".encode("utf-8")
but there is no fix length for emojis . β Farleighunicodedata
butπ
did not exist in the unicodedata db on Python 2.7 so YMMV. β Onetooneb'\xf0\x9f\x98\x98'
andb'\xe2\x97\xbc\xef\xb8\x8f'
but how can i understand there is only one emoji ? β Farleigh