Last active
June 23, 2024 19:33
-
-
Save raym/a507a660674c984fa9139abf438c84d2 to your computer and use it in GitHub Desktop.
Strip emoji characters in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def strip_emojis(text) | |
text = text.force_encoding('utf-8').encode | |
clean = "" | |
# symbols & pics | |
regex = /[\u{1f300}-\u{1f5ff}]/ | |
clean = text.gsub(regex, "") | |
# enclosed chars | |
regex = /[\u{2500}-\u{2BEF}]/ | |
clean = clean.gsub(regex, "") | |
# emoticons | |
regex = /[\u{1f600}-\u{1f64f}]/ | |
clean = clean.gsub(regex, "") | |
#dingbats | |
regex = /[\u{2702}-\u{27b0}]/ | |
clean = clean.gsub(regex, "") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment