mathiasbynens / emoji-regex

A regular expression to match all Emoji-only symbols as per the Unicode Standard.
https://mths.be/emoji-regex
MIT License
1.73k stars 174 forks source link

Match doesn't include entire emoji for some emojis. #35

Closed ZDemeter closed 5 years ago

ZDemeter commented 6 years ago

When matching a string for emojis, the returned match does not include the entire emoji.

For example,

let emojiString = 'peace hand -> ✌️';
let match = EmojiRegex.exec(emojiString);

console.log(✌️===match[0]); //false

Instead match[0] returns

The match doesn't include the entire emoji. An emoji consists of 2 16-bit code points, but for some emojis, only the first code point is matched and returned, giving these weird emojis in browsers.

(A couple of minutes in https://thekevinscott.com/emojis-in-javascript/ , and I can pretend to know anything about emojis 👍 )

mathiasbynens commented 5 years ago

I cannot reproduce the issue using the latest version:

const emojiRegex = require('emoji-regex');

const string = '\u270C\uFE0F'; // '✌️'
console.log(
    string.match(emojiRegex())
);
// → [ '✌️' ]

Closing as fixed.