Skip to content

Instantly share code, notes, and snippets.

@Davisy
Forked from slowkow/remove-emoji.py
Created April 19, 2020 10:31
Show Gist options
  • Save Davisy/64d89c23c1e6fe75b6c8bf811632a499 to your computer and use it in GitHub Desktop.
Save Davisy/64d89c23c1e6fe75b6c8bf811632a499 to your computer and use it in GitHub Desktop.
Remove all traces of emoji from a text file.
#!/usr/bin/env python
"""
Remove emoji from a text file and print it to stdout.
Usage
-----
python remove-emoji.py input.txt > output.txt
"""
import re
import sys
# https://stackoverflow.com/a/49146722/330558
def remove_emoji(string):
emoji_pattern = re.compile("["
u"\U0001F600-\U0001F64F" # emoticons
u"\U0001F300-\U0001F5FF" # symbols & pictographs
u"\U0001F680-\U0001F6FF" # transport & map symbols
u"\U0001F1E0-\U0001F1FF" # flags (iOS)
u"\U00002702-\U000027B0"
u"\U000024C2-\U0001F251"
"]+", flags=re.UNICODE)
return emoji_pattern.sub(r'', string)
if __name__ == '__main__':
text = open(sys.argv[1]).read()
text = remove_emoji(text)
print(text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment