A Ruby regular expression for matching Unicode Emoji symbols.
This is based upon the fantastic work from Mathias Bynens' emoji-test-regex-pattern package. emoji-test-regex-pattern is cleverly assembled based upon data from the Unicode Consortium.
The regular expressions provided herein are derived from that package.
gem install emoji_regexemoji_regex provides the EmojiRegex::Regex regular expression, which matches emoji, as defined by the Unicode standard's emoji-test data file.
require 'emoji_regex'
text = <<TEXT
\u{231A}: β default Emoji presentation character (Emoji_Presentation)
\u{2194}\u{FE0F}: βοΈ default text presentation character with Emoji variation selector
\u{1F469}: π© Emoji modifier base (Emoji_Modifier_Base)
\u{1F469}\u{1F3FF}: π©πΏ Emoji modifier base followed by a modifier
TEXT
text.scan EmojiRegex::Regex do |emoji|
puts "Matched sequence #{emoji} β code points: #{emoji.length}"
endConsole output:
Matched sequence β β code points: 1
Matched sequence β β code points: 1
Matched sequence βοΈ β code points: 2
Matched sequence βοΈ β code points: 2
Matched sequence π© β code points: 1
Matched sequence π© β code points: 1
Matched sequence π©πΏ β code points: 2
Matched sequence π©πΏ β code points: 2
Note: The above code and output are verified as part of the spec suite.
To install all the Ruby and Javascript dependencies, you can run:
bin/setupTo update the Ruby source files based on the emoji-regex library:
bundle exec rake regenerateA spec suite is provided, which can be run as:
bundle exec rake specSince Version 14.0.0, Ruby Emoji Regex's versions have followed that of the Unicode standard itself.
Ruby Emoji Regex is based upon the emoji-test-regex-pattern package.
- If a patch revision of
emoji-test-regex-patternis released, and if its changes affect the Ruby port meaningfully, a version will be released with the same or greater patch version. - If a change is required to correct a bug specific to the Ruby port, the patch number will be incremented.
While Ruby Emoji Regex uses features which should function on any Ruby version, it is explicitly intended to work on MRI Ruby versions which are currently within normal maintenance according to the Ruby team.
- Update the version in emoji_regex.gemspec
rake release