A small Ruby library which provides Unicode Emoji data and regexes.
Also includes a categorized list of recommended Emoji.
Emoji version: 5.0
Supported Rubies: 2.5, 2.4, 2.3, 2.2
Unsupported Rubies, but may still work: 2.1
gem "unicode-emoji"
Five Emoji regexes are included, which are compiled out of various Emoji Unicode data.
require "unicode/emoji"
string = "String which contains all kinds of emoji:
- Singleton Emoji: ๐ด
- Textual singleton Emoji with Emoji variation: โถ๏ธ
- Emoji with skin tone modifier: ๐๐ฝ
- Region flag: ๐ต๐น
- Sub-Region flag: ๐ด๓ ง๓ ข๓ ณ๓ ฃ๓ ด๓ ฟ
- Keycap sequence: 2๏ธโฃ
- Sequence using ZWJ (zero width joiner): ๐คพ๐ฝโโ๏ธ
"
string.scan(Unicode::Emoji::REGEX) # => ["๐ด", "โถ๏ธ", "๐๐ฝ", "๐ต๐น", "๐ด๓ ง๓ ข๓ ณ๓ ฃ๓ ด๓ ฟ", "2๏ธโฃ", "๐คพ๐ฝโโ๏ธ"]
Regex | Description | Example Matches | Example Non-Matches |
---|---|---|---|
Unicode::Emoji::REGEX |
Matches (non-textual) singleton Emoji (except for singleton components, like a skin tone modifier without base Emoji) and all kind of valid Emoji sequences, but restrict ZWJ and TAG sequences to recommended sequences | ๐ด , โถ๏ธ , ๐๐ฝ , ๐ต๐น , 2๏ธโฃ , ๐ด๓ ง๓ ข๓ ณ๓ ฃ๓ ด๓ ฟ , ๐คพ๐ฝโโ๏ธ |
๐ด๏ธ , โถ , ๐ป , ๐ต๐ต , ๐ด๓ ง๓ ข๓ ก๓ ง๓ ข๓ ฟ , ๐ค โ๐คข |
Unicode::Emoji::REGEX_VALID |
Matches (non-textual) singleton Emoji (except for singleton components, like a skin tone modifier without base Emoji) and all kind of valid Emoji sequences | ๐ด , โถ๏ธ , ๐๐ฝ , ๐ต๐น , 2๏ธโฃ , ๐ด๓ ง๓ ข๓ ณ๓ ฃ๓ ด๓ ฟ , ๐ด๓ ง๓ ข๓ ก๓ ง๓ ข๓ ฟ , ๐คพ๐ฝโโ๏ธ , ๐ค โ๐คข |
๐ด๏ธ , โถ , ๐ป , ๐ต๐ต |
Unicode::Emoji::REGEX_BASIC |
Matches (non-textual) singleton Emoji (except for singleton components, like a skin tone modifier without base Emoji), but no sequences | ๐ด , โถ๏ธ |
๐ด๏ธ , โถ , ๐ป , ๐๐ฝ , ๐ต๐น , ๐ต๐ต ,2๏ธโฃ , ๐ด๓ ง๓ ข๓ ณ๓ ฃ๓ ด๓ ฟ , ๐ด๓ ง๓ ข๓ ก๓ ง๓ ข๓ ฟ , ๐คพ๐ฝโโ๏ธ , ๐ค โ๐คข |
Unicode::Emoji::REGEX_TEXT |
Matches only textual singleton Emoji (except for singleton components, like digit 1) | ๐ด๏ธ , โถ |
๐ด , โถ๏ธ , ๐ป , ๐๐ฝ , ๐ต๐น , ๐ต๐ต ,2๏ธโฃ , ๐ด๓ ง๓ ข๓ ณ๓ ฃ๓ ด๓ ฟ , ๐ด๓ ง๓ ข๓ ก๓ ง๓ ข๓ ฟ , ๐คพ๐ฝโโ๏ธ , ๐ค โ๐คข |
Unicode::Emoji::REGEX_ANY |
Matches any Emoji-related codepoint (but no variation selectors or tags) | ๐ด , โถ , ๐ป , ๐ , ๐ฝ , ๐ต , ๐น , 2 , ๐ด , ๐คพ , โ , ๐ค , ๐คข |
- |
More info about valid vs. recommended emoji in this blog article on Emojipedia.
Use Unicode::Emoji::LIST
or the list method to get a grouped (and ordered) list of Emoji:
Unicode::Emoji.list.keys
# => ["Smileys & People", "Animals & Nature", "Food & Drink", "Travel & Places", "Activities", "Objects", "Symbols", "Flags"]
Unicode::Emoji.list("Food & Drink").keys
# => ["food-fruit", "food-vegetable", "food-prepared", "food-asian", "food-sweet", "drink", "dishware"]
Unicode::Emoji.list("Food & Drink", "food-asian")
=> ["๐ฑ", "๐", "๐", "๐", "๐", "๐", "๐", "๐ ", "๐ข", "๐ฃ", "๐ค", "๐ฅ", "๐ก", "\u{1F95F}", "\u{1F960}", "\u{1F961}"]
A markdown file with all recommended emoji can be found in this gist.
Allows you to access the codepoint data form Unicode's emoji-data.txt file:
require "unicode/emoji"
Unicode::Emoji.properties "โ" # => ["Emoji", "Emoji_Modifier_Base"]
- Unicodeยฎ Technical Standard #51
- Emoji data
- Emoji categories
- Ruby gem which displays Emoji sequence names
- Part of unicode-x
- Copyright (C) 2017, 2018 Jan Lelis http://janlelis.com. Released under the MIT license.
- Unicode data: http://www.unicode.org/copyright.html#Exhibit1