Substitute Emoji with its description or name

I’m working on getting all emojis from a text retrieved form an API. What I’d like to do is substitute each emoji for its description or name.

I’m working on Python 3.4 and my current approach is accesing the unicode’s name with unicodedata like this:

nname = unicodedata.name(my_unicode)

And I’m substituting with re.sub:

re.sub('[U0001F602-U0001F64F]', 'new string', str(orig_string))

I’ve tried re.search and then accessing matches and replacing strings (don’t work with regex) but haven’t been able to solve this.

Is there a way of getting a callback for each substitution that re.sub does? Any other route is also appreciated.


Source: regex

Leave a Reply