Ruby
Clone or download
Latest commit 77cbfff Jun 5, 2018

README.md

Unicode::Emoji [version] [travis]

A small Ruby library which provides Unicode Emoji data and regexes.

Also includes a categorized list of recommended Emoji.

Emoji version: 11.0

Supported Rubies: 2.5, 2.4, 2.3

If you are stuck on an older Ruby version, checkout the latest 0.9 version of this gem.

Gemfile

gem "unicode-emoji"

Usage

Regex

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.

List

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.

Properties

Allows you to access the codepoint data form Unicode's emoji-data.txt file:

require "unicode/emoji"

Unicode::Emoji.properties "" # => ["Emoji", "Emoji_Modifier_Base"]

Also See

MIT