0

I'm receiving emojies from a chat application and i want to separate each single emoji when there are multiple emojies. I'm able to catch a single emoji as an unicode value.but split function does't work for multiple emoji unicode values.This code is for a single emoji

def getEmoji(data)
    sleepy_face = [u'\U0001F6CC', u'\U0001F634', u'\U0001F4A4']

    if (data in sleepy_face):
        return emoji.emojize('Are you sleepy? :slightly_smiling_face:', use_aliases=True)

I tried this to separate multiple emojies

encode_data=data.encode('raw_unicode_escape')
find_data = encode_data.split(b'\\\\')
for extract_data in find_data:
    print(extract_data)
    if (extract_data in sleepy_face):
        return emoji.emojize('Are you sleepy? :slightly_smiling_face:', use_aliases=True)  

Split method returns again encode_data. How can i solve this?

2
  • Is it possible to use NLTK tweetNLP for a same result? Commented Jul 20, 2017 at 5:36
  • Seems like in Python they are prepended with a 'u' fileformat.info/info/unicode/char/1f634/index.htm Perhaps that might help Commented Jul 20, 2017 at 5:38

1 Answer 1

1
import re
data = u'\U0001f6cc\U0001f634\U0001f4a4'
for i in re.findall(ur'..', data):
    print i
    if i in sleepy_face:
        return 

when run:

re.findall(ur'.', data) 

you will get:

[u'\ud83d', u'\udecc', u'\ud83d', u'\ude34', u'\ud83d', u'\udca4']

3 emojies == 6 unicode chars.

Another way:

s =  u'\U0001F6CCabc\U0001F634bcd\U0001F4A4'
for i in re.findall(ur'([\ud000-\udfff][\ud000-\udfff])', s): 
    # change range '\ud000'-'\udfff'
    print i 

thx @IgnacioVazquez-Abrams. Edit: if Python with UCS-4:

for i in re.findall(".", data):
    if i in sleepy_face:
        print i
Sign up to request clarification or add additional context in comments.

2 Comments

Only if you're using a UCS-2 build of Python.
thx @IgnacioVazquez-Abrams. if UCS-4(or python3), 1 emojie = 1 unicode char.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.