Skip to content

Instantly share code, notes, and snippets.

@raym
Last active June 23, 2024 19:33
Show Gist options
  • Save raym/a507a660674c984fa9139abf438c84d2 to your computer and use it in GitHub Desktop.
Save raym/a507a660674c984fa9139abf438c84d2 to your computer and use it in GitHub Desktop.
Strip emoji characters in Ruby
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