PYTHON AND EMOJIS (OPTIONAL)
Listing A.14 displays the contents remove_emojis.py that illustrates how to remove emojis from a text string.
Listing A.14: remove_emojis.py
import re
import emoji
text = "I want a Chicago deep dish pizza tonight \U0001f600"
print("text:")
print(text)
print()
emoji_pattern = re.compile("[" "\U0001F1E0-\U0001F6FF" "]+", flags=re.UNICODE)
text = emoji_pattern.sub(r"", text)
text = "".join([x for x in text if x not in emoji.UNICODE_EMOJI])
print("text:")
print(text)
print()
Listing A.14 starts with two import statements, followed by initializing the variable text with a text string, whose contents are displayed. The next portion of Listing A.14 defines the variable emoji_pattern as a regular expression that represents a range of Unicode values for emojis.
The next portion of Listing A.14 sets the variable text equal to the set of non emoji characters contained in the previously...