79

I need help for how to detect if an input contains a Japanese emoji/emoticon.

Currently my character set is charset=utf-8. On inputting text, the user can enter Japanese characters/alpanumerics/symbols but if they insert an emoji, onsubmit JavaScript will check if there is an emoji, error message will display.

I can't get this to work because I have no idea on how to detect an emoji in JavaScript?

Nathaniel Flick
  • 2,902
  • 2
  • 22
  • 31
user2699175
  • 929
  • 2
  • 9
  • 16

11 Answers11

109

The answers might work but are terrible because they rely on unicode ranges that are unreadable and somewhat "magic" because it's not always clear where do they come from and why they work, not to mention they're not resilient to new emojis being added to the spec.

Major browsers now support unicode property escape which allows for matching emojis based on their belonging in the Emoji unicode category: \p{Emoji} matches an emoji, \P{Emoji} matches a non-emoji.

Note that officially, 0123456789#* and other characters are emojis too, so the property escape you might want to use is not Emoji but rather Extended_Pictographic which denotes all the characters typically understood as emojis!

Make sure to include the u flag at the end.

console.log(
  /\p{Emoji}/u.test('flowers'), // false :)
  /\p{Emoji}/u.test('flowers '), // true :)
  /\p{Emoji}/u.test('flowers 123'), // true :( 
)
console.log(
  /\p{Extended_Pictographic}/u.test('flowers'), // false :)
  /\p{Extended_Pictographic}/u.test('flowers '), // true :)
  /\p{Extended_Pictographic}/u.test('flowers 123'), // false :)
)

This works fine for detecting emojis, but if you want to use the same regex to extract them, you might be surprised with its behavior, since some emojis that appear as one character are actually several characters. They're what we call emoji sequences, more about them in this question

const regex = /\p{Extended_Pictographic}/ug
const family = '‍‍' // "family 
console.log(family.length) // not 1, but 8!
console.log(regex.test(family)) // true, as expected
console.log(family.match(regex)) // not [family], but [man, woman, girl]

See also:

Nino Filiu
  • 16,660
  • 11
  • 54
  • 84
  • 5
    This should be accepted answer. All other regexes aren't really maintainable. – jtompl Oct 05 '20 at 10:53
  • 1
    The Emoji class seems to match numbers as well. Try this: `/^\p{Emoji}*$/u.test("123")` A fix for that would be this regexp: `/(?=\p{Emoji})(?!\p{Number})/u` – Bronzdragon Oct 15 '20 at 16:45
  • 2
    Ah, thanks @Bronzdragon ! The issue is more complex, I asked [another question on the subject](https://stackoverflow.com/q/64389323/8186898) and mentionned your fix, and updated the above answer, because your fix doesn't handle `*` and `#` being emojis too – Nino Filiu Oct 16 '20 at 13:57
  • 3
    This *is* a nice simple answer, but be warned it does not interpret multi-part emoji as you might expect. eg: `'‍‍'.match(/\p{Extended_Pictographic}/ug) -> ["","",""]` – SimplGy Jul 11 '21 at 22:32
  • @SimplGy thanks for catching that gotcha! I edited my answer accordingly. – Nino Filiu Aug 05 '21 at 08:20
36

You can use the following regex:

/(?:[\u2700-\u27bf]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff]|[\u0023-\u0039]\ufe0f?\u20e3|\u3299|\u3297|\u303d|\u3030|\u24c2|\ud83c[\udd70-\udd71]|\ud83c[\udd7e-\udd7f]|\ud83c\udd8e|\ud83c[\udd91-\udd9a]|\ud83c[\udde6-\uddff]|\ud83c[\ude01-\ude02]|\ud83c\ude1a|\ud83c\ude2f|\ud83c[\ude32-\ude3a]|\ud83c[\ude50-\ude51]|\u203c|\u2049|[\u25aa-\u25ab]|\u25b6|\u25c0|[\u25fb-\u25fe]|\u00a9|\u00ae|\u2122|\u2139|\ud83c\udc04|[\u2600-\u26FF]|\u2b05|\u2b06|\u2b07|\u2b1b|\u2b1c|\u2b50|\u2b55|\u231a|\u231b|\u2328|\u23cf|[\u23e9-\u23f3]|[\u23f8-\u23fa]|\ud83c\udccf|\u2934|\u2935|[\u2190-\u21ff])/g

If you just want to remove it from the string, you can do something like this.

function removeEmojis (string) {
  var regex = /(?:[\u2700-\u27bf]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff]|[\u0023-\u0039]\ufe0f?\u20e3|\u3299|\u3297|\u303d|\u3030|\u24c2|\ud83c[\udd70-\udd71]|\ud83c[\udd7e-\udd7f]|\ud83c\udd8e|\ud83c[\udd91-\udd9a]|\ud83c[\udde6-\uddff]|\ud83c[\ude01-\ude02]|\ud83c\ude1a|\ud83c\ude2f|\ud83c[\ude32-\ude3a]|\ud83c[\ude50-\ude51]|\u203c|\u2049|[\u25aa-\u25ab]|\u25b6|\u25c0|[\u25fb-\u25fe]|\u00a9|\u00ae|\u2122|\u2139|\ud83c\udc04|[\u2600-\u26FF]|\u2b05|\u2b06|\u2b07|\u2b1b|\u2b1c|\u2b50|\u2b55|\u231a|\u231b|\u2328|\u23cf|[\u23e9-\u23f3]|[\u23f8-\u23fa]|\ud83c\udccf|\u2934|\u2935|[\u2190-\u21ff])/g;

  return string.replace(regex, '');
}
kos
  • 5,044
  • 1
  • 17
  • 35
lucas
  • 1,105
  • 8
  • 14
  • 9
    Great answer for me. However a mistake in the regex causes this to also match right brackets ([). Looks like just a mistake from copying and pasting code, but Lucas please fix. Fixed regex here: https://pastebin.com/0VZZKfWf – Marc Guiselin May 31 '17 at 01:31
  • 7
    How does this handle new Emoji that get added to the spec? – Jamie Street Nov 02 '17 at 18:06
  • 1
    @JamieStreet did you already try it? If it isn't working probably the regex, unfortunately, needs to be adjusted – lucas Nov 03 '17 at 14:51
  • +1. And I wonder if it might benefit from being updated like the regex at https://stackoverflow.com/a/20208095/470749 – Ryan Sep 10 '18 at 23:33
  • It's working with all the emojis listed here: https://getemoji.com/ – lucas Feb 08 '21 at 09:46
17

First of all, you cannot rely on ECMAScript 2018+ compliant \p{Emoji} (at least at the time of writing). It really matches some 0123456789#* non-emoji chars (see Nino Filiu's answer). See Why do Unicode emoji property escapes match numbers? for more details.

If you target the most up-to-date ECMAScript implementation and you can use the v flag, the best construct to match a single emoji is \p{RGI_Emoji}:

console.log( /\p{RGI_Emoji}/v.test('flowers 123') );     // => false
console.log( /\p{RGI_Emoji}/v.test('flowers ') ); // => true
console.log( [...'flowers '.matchAll(/\p{RGI_Emoji}/vg)].length ); // => 3
console.log( [...'flowers '.matchAll(/\p{RGI_Emoji}/vg)] ); // => [[""],[""],[""]]

To test if there are any emoji chars in a string in JavaScript, you can use the following ECMAScript 2018+ compliant solution (mind the u flag):

const regex_emoji = /[\p{Extended_Pictographic}\u{1F3FB}-\u{1F3FF}\u{1F9B0}-\u{1F9B3}]/u;
console.log( regex_emoji.test('flowers 123') );     // => false
console.log( regex_emoji.test('flowers ') ); // => true

You can even extract one or more emoji char sequences using this pattern (note the added g flag to find all occurrences and + to match one or more consecutive occurrences of the character class pattern):

const regex_emoji = /[\p{Extended_Pictographic}\u{1F3FB}-\u{1F3FF}\u{1F9B0}-\u{1F9B3}]+/gu;
console.log( 'flowers 123'.match(regex_emoji) );     // => null
console.log( 'flowers '.match(regex_emoji) ); // => [ "" ]

In a nutshell, the Extended_Pictographic Unicode category class matches most emoji chars except for some Emoji_Components, that is, light skin to dark skin mode chars (\u{1F3FB}-\u{1F3FF}) and red-haired to white-haired chars (\u{1F9B0}-\u{1F9B3}).

To count, or extract emojis as an array of single chars or consecutive sequences (like in the second code snippet from above) from longer texts and perform other actions on emojis, you can use a custom regex (like in Scott Weaver's answer). It is safer to use the longer, escaped version. However, there are 4702 emoji characters defined in the Emoji Keyboard/Display Test Data for UTR #51 (Version: 14.0) file. Thus, the (ES5 compliant, works even in IE) regex to match a single emoji char is

var EmojiPattern = /[#*0-9]\uFE0F?\u20E3|\u00A9\uFE0F?|[\u00AE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA]\uFE0F?|[\u231A\u231B]|[\u2328\u23CF]\uFE0F?|[\u23E9-\u23EC]|[\u23ED-\u23EF]\uFE0F?|\u23F0|[\u23F1\u23F2]\uFE0F?|\u23F3|[\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC]\uFE0F?|[\u25FD\u25FE]|[\u2600-\u2604\u260E\u2611]\uFE0F?|[\u2614\u2615]|\u2618\uFE0F?|\u261D(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|[\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642]\uFE0F?|[\u2648-\u2653]|[\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E]\uFE0F?|\u267F|\u2692\uFE0F?|\u2693|[\u2694-\u2697\u2699\u269B\u269C\u26A0]\uFE0F?|\u26A1|\u26A7\uFE0F?|[\u26AA\u26AB]|[\u26B0\u26B1]\uFE0F?|[\u26BD\u26BE\u26C4\u26C5]|\u26C8\uFE0F?|\u26CE|[\u26CF\u26D1\u26D3]\uFE0F?|\u26D4|\u26E9\uFE0F?|\u26EA|[\u26F0\u26F1]\uFE0F?|[\u26F2\u26F3]|\u26F4\uFE0F?|\u26F5|[\u26F7\u26F8]\uFE0F?|\u26F9(?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF](?:\u200D[\u2640\u2642]\uFE0F?)?|\uFE0F(?:\u200D[\u2640\u2642]\uFE0F?)?)?|[\u26FA\u26FD]|\u2702\uFE0F?|\u2705|[\u2708\u2709]\uFE0F?|[\u270A\u270B](?:\uD83C[\uDFFB-\uDFFF])?|[\u270C\u270D](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|\u270F\uFE0F?|[\u2712\u2714\u2716\u271D\u2721]\uFE0F?|\u2728|[\u2733\u2734\u2744\u2747]\uFE0F?|[\u274C\u274E\u2753-\u2755\u2757]|\u2763\uFE0F?|\u2764(?:\u200D(?:\uD83D\uDD25|\uD83E\uDE79)|\uFE0F(?:\u200D(?:\uD83D\uDD25|\uD83E\uDE79))?)?|[\u2795-\u2797]|\u27A1\uFE0F?|[\u27B0\u27BF]|[\u2934\u2935\u2B05-\u2B07]\uFE0F?|[\u2B1B\u2B1C\u2B50\u2B55]|[\u3030\u303D\u3297\u3299]\uFE0F?|\uD83C(?:[\uDC04\uDCCF]|[\uDD70\uDD71\uDD7E\uDD7F]\uFE0F?|[\uDD8E\uDD91-\uDD9A]|\uDDE6\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF]|\uDDE7\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF]|\uDDE8\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF]|\uDDE9\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF]|\uDDEA\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA]|\uDDEB\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7]|\uDDEC\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE]|\uDDED\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA]|\uDDEE\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9]|\uDDEF\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5]|\uDDF0\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF]|\uDDF1\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE]|\uDDF2\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF]|\uDDF3\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF]|\uDDF4\uD83C\uDDF2|\uDDF5\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE]|\uDDF6\uD83C\uDDE6|\uDDF7\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC]|\uDDF8\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF]|\uDDF9\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF]|\uDDFA\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF]|\uDDFB\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA]|\uDDFC\uD83C[\uDDEB\uDDF8]|\uDDFD\uD83C\uDDF0|\uDDFE\uD83C[\uDDEA\uDDF9]|\uDDFF\uD83C[\uDDE6\uDDF2\uDDFC]|\uDE01|\uDE02\uFE0F?|[\uDE1A\uDE2F\uDE32-\uDE36]|\uDE37\uFE0F?|[\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20]|[\uDF21\uDF24-\uDF2C]\uFE0F?|[\uDF2D-\uDF35]|\uDF36\uFE0F?|[\uDF37-\uDF7C]|\uDF7D\uFE0F?|[\uDF7E-\uDF84]|\uDF85(?:\uD83C[\uDFFB-\uDFFF])?|[\uDF86-\uDF93]|[\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F]\uFE0F?|[\uDFA0-\uDFC1]|\uDFC2(?:\uD83C[\uDFFB-\uDFFF])?|[\uDFC3\uDFC4](?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF](?:\u200D[\u2640\u2642]\uFE0F?)?)?|[\uDFC5\uDFC6]|\uDFC7(?:\uD83C[\uDFFB-\uDFFF])?|[\uDFC8\uDFC9]|\uDFCA(?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF](?:\u200D[\u2640\u2642]\uFE0F?)?)?|[\uDFCB\uDFCC](?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF](?:\u200D[\u2640\u2642]\uFE0F?)?|\uFE0F(?:\u200D[\u2640\u2642]\uFE0F?)?)?|[\uDFCD\uDFCE]\uFE0F?|[\uDFCF-\uDFD3]|[\uDFD4-\uDFDF]\uFE0F?|[\uDFE0-\uDFF0]|\uDFF3(?:\u200D(?:\u26A7\uFE0F?|\uD83C\uDF08)|\uFE0F(?:\u200D(?:\u26A7\uFE0F?|\uD83C\uDF08))?)?|\uDFF4(?:\u200D\u2620\uFE0F?|\uDB40\uDC67\uDB40\uDC62\uDB40(?:\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDC73\uDB40\uDC63\uDB40\uDC74|\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F)?|[\uDFF5\uDFF7]\uFE0F?|[\uDFF8-\uDFFF])|\uD83D(?:[\uDC00-\uDC07]|\uDC08(?:\u200D\u2B1B)?|[\uDC09-\uDC14]|\uDC15(?:\u200D\uD83E\uDDBA)?|[\uDC16-\uDC3A]|\uDC3B(?:\u200D\u2744\uFE0F?)?|[\uDC3C-\uDC3E]|\uDC3F\uFE0F?|\uDC40|\uDC41(?:\u200D\uD83D\uDDE8\uFE0F?|\uFE0F(?:\u200D\uD83D\uDDE8\uFE0F?)?)?|[\uDC42\uDC43](?:\uD83C[\uDFFB-\uDFFF])?|[\uDC44\uDC45]|[\uDC46-\uDC50](?:\uD83C[\uDFFB-\uDFFF])?|[\uDC51-\uDC65]|[\uDC66\uDC67](?:\uD83C[\uDFFB-\uDFFF])?|\uDC68(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?|[\uDC68\uDC69]\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92])|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFC-\uDFFF]|[\uDDAF-\uDDB3\uDDBC\uDDBD])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFD-\uDFFF]|[\uDDAF-\uDDB3\uDDBC\uDDBD])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|[\uDDAF-\uDDB3\uDDBC\uDDBD])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFD\uDFFF]|[\uDDAF-\uDDB3\uDDBC\uDDBD])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFE]|[\uDDAF-\uDDB3\uDDBC\uDDBD])))?))?|\uDC69(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?[\uDC68\uDC69]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?|\uDC69\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92])|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFF]|\uDC8B\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFC-\uDFFF]|[\uDDAF-\uDDB3\uDDBC\uDDBD])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFF]|\uDC8B\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFD-\uDFFF]|[\uDDAF-\uDDB3\uDDBC\uDDBD])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFF]|\uDC8B\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|[\uDDAF-\uDDB3\uDDBC\uDDBD])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFF]|\uDC8B\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFD\uDFFF]|[\uDDAF-\uDDB3\uDDBC\uDDBD])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFF]|\uDC8B\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFE]|[\uDDAF-\uDDB3\uDDBC\uDDBD])))?))?|\uDC6A|[\uDC6B-\uDC6D](?:\uD83C[\uDFFB-\uDFFF])?|\uDC6E(?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF](?:\u200D[\u2640\u2642]\uFE0F?)?)?|\uDC6F(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDC70\uDC71](?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF](?:\u200D[\u2640\u2642]\uFE0F?)?)?|\uDC72(?:\uD83C[\uDFFB-\uDFFF])?|\uDC73(?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF](?:\u200D[\u2640\u2642]\uFE0F?)?)?|[\uDC74-\uDC76](?:\uD83C[\uDFFB-\uDFFF])?|\uDC77(?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF](?:\u200D[\u2640\u2642]\uFE0F?)?)?|\uDC78(?:\uD83C[\uDFFB-\uDFFF])?|[\uDC79-\uDC7B]|\uDC7C(?:\uD83C[\uDFFB-\uDFFF])?|[\uDC7D-\uDC80]|[\uDC81\uDC82](?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF](?:\u200D[\u2640\u2642]\uFE0F?)?)?|\uDC83(?:\uD83C[\uDFFB-\uDFFF])?|\uDC84|\uDC85(?:\uD83C[\uDFFB-\uDFFF])?|[\uDC86\uDC87](?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF](?:\u200D[\u2640\u2642]\uFE0F?)?)?|[\uDC88-\uDC8E]|\uDC8F(?:\uD83C[\uDFFB-\uDFFF])?|\uDC90|\uDC91(?:\uD83C[\uDFFB-\uDFFF])?|[\uDC92-\uDCA9]|\uDCAA(?:\uD83C[\uDFFB-\uDFFF])?|[\uDCAB-\uDCFC]|\uDCFD\uFE0F?|[\uDCFF-\uDD3D]|[\uDD49\uDD4A]\uFE0F?|[\uDD4B-\uDD4E\uDD50-\uDD67]|[\uDD6F\uDD70\uDD73]\uFE0F?|\uDD74(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|\uDD75(?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF](?:\u200D[\u2640\u2642]\uFE0F?)?|\uFE0F(?:\u200D[\u2640\u2642]\uFE0F?)?)?|[\uDD76-\uDD79]\uFE0F?|\uDD7A(?:\uD83C[\uDFFB-\uDFFF])?|[\uDD87\uDD8A-\uDD8D]\uFE0F?|\uDD90(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|[\uDD95\uDD96](?:\uD83C[\uDFFB-\uDFFF])?|\uDDA4|[\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA]\uFE0F?|[\uDDFB-\uDE2D]|\uDE2E(?:\u200D\uD83D\uDCA8)?|[\uDE2F-\uDE34]|\uDE35(?:\u200D\uD83D\uDCAB)?|\uDE36(?:\u200D\uD83C\uDF2B\uFE0F?)?|[\uDE37-\uDE44]|[\uDE45-\uDE47](?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF](?:\u200D[\u2640\u2642]\uFE0F?)?)?|[\uDE48-\uDE4A]|\uDE4B(?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF](?:\u200D[\u2640\u2642]\uFE0F?)?)?|\uDE4C(?:\uD83C[\uDFFB-\uDFFF])?|[\uDE4D\uDE4E](?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF](?:\u200D[\u2640\u2642]\uFE0F?)?)?|\uDE4F(?:\uD83C[\uDFFB-\uDFFF])?|[\uDE80-\uDEA2]|\uDEA3(?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF](?:\u200D[\u2640\u2642]\uFE0F?)?)?|[\uDEA4-\uDEB3]|[\uDEB4-\uDEB6](?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF](?:\u200D[\u2640\u2642]\uFE0F?)?)?|[\uDEB7-\uDEBF]|\uDEC0(?:\uD83C[\uDFFB-\uDFFF])?|[\uDEC1-\uDEC5]|\uDECB\uFE0F?|\uDECC(?:\uD83C[\uDFFB-\uDFFF])?|[\uDECD-\uDECF]\uFE0F?|[\uDED0-\uDED2\uDED5-\uDED7\uDEDD-\uDEDF]|[\uDEE0-\uDEE5\uDEE9]\uFE0F?|[\uDEEB\uDEEC]|[\uDEF0\uDEF3]\uFE0F?|[\uDEF4-\uDEFC\uDFE0-\uDFEB\uDFF0])|\uD83E(?:\uDD0C(?:\uD83C[\uDFFB-\uDFFF])?|[\uDD0D\uDD0E]|\uDD0F(?:\uD83C[\uDFFB-\uDFFF])?|[\uDD10-\uDD17]|[\uDD18-\uDD1F](?:\uD83C[\uDFFB-\uDFFF])?|[\uDD20-\uDD25]|\uDD26(?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF](?:\u200D[\u2640\u2642]\uFE0F?)?)?|[\uDD27-\uDD2F]|[\uDD30-\uDD34](?:\uD83C[\uDFFB-\uDFFF])?|\uDD35(?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF](?:\u200D[\u2640\u2642]\uFE0F?)?)?|\uDD36(?:\uD83C[\uDFFB-\uDFFF])?|[\uDD37-\uDD39](?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF](?:\u200D[\u2640\u2642]\uFE0F?)?)?|\uDD3A|\uDD3C(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD3D\uDD3E](?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF](?:\u200D[\u2640\u2642]\uFE0F?)?)?|[\uDD3F-\uDD45\uDD47-\uDD76]|\uDD77(?:\uD83C[\uDFFB-\uDFFF])?|[\uDD78-\uDDB4]|[\uDDB5\uDDB6](?:\uD83C[\uDFFB-\uDFFF])?|\uDDB7|[\uDDB8\uDDB9](?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF](?:\u200D[\u2640\u2642]\uFE0F?)?)?|\uDDBA|\uDDBB(?:\uD83C[\uDFFB-\uDFFF])?|[\uDDBC-\uDDCC]|[\uDDCD-\uDDCF](?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF](?:\u200D[\u2640\u2642]\uFE0F?)?)?|\uDDD0|\uDDD1(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:\uDD1D\u200D\uD83E\uDDD1|[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFC-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF]|[\uDDAF-\uDDB3\uDDBC\uDDBD])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFD-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF]|[\uDDAF-\uDDB3\uDDBC\uDDBD])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF]|[\uDDAF-\uDDB3\uDDBC\uDDBD])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFD\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF]|[\uDDAF-\uDDB3\uDDBC\uDDBD])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFE]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF]|[\uDDAF-\uDDB3\uDDBC\uDDBD])))?))?|[\uDDD2\uDDD3](?:\uD83C[\uDFFB-\uDFFF])?|\uDDD4(?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF](?:\u200D[\u2640\u2642]\uFE0F?)?)?|\uDDD5(?:\uD83C[\uDFFB-\uDFFF])?|[\uDDD6-\uDDDD](?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF](?:\u200D[\u2640\u2642]\uFE0F?)?)?|[\uDDDE\uDDDF](?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDDE0-\uDDFF\uDE70-\uDE74\uDE78-\uDE7C\uDE80-\uDE86\uDE90-\uDEAC\uDEB0-\uDEBA\uDEC0-\uDEC2]|[\uDEC3-\uDEC5](?:\uD83C[\uDFFB-\uDFFF])?|[\uDED0-\uDED9\uDEE0-\uDEE7]|\uDEF0(?:\uD83C[\uDFFB-\uDFFF])?|\uDEF1(?:\uD83C(?:\uDFFB(?:\u200D\uD83E\uDEF2\uD83C[\uDFFC-\uDFFF])?|\uDFFC(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFD-\uDFFF])?|\uDFFD(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])?|\uDFFE(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFD\uDFFF])?|\uDFFF(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFE])?))?|[\uDEF2-\uDEF6](?:\uD83C[\uDFFB-\uDFFF])?)/g;

See the regex demo. The g flag at the end means this regex can match all occurrences in the input string.

The pattern is created dynamically from the list of emojis and contracted using a regex trie.

See this JavaScript demo:

var text = 'flowers ';
// Detecting if there is at least one emoji
console.log( emoji_detection_regex.test(text) );             // => true
// Counting emojis
console.log( (text.match(emoji_count_regex) || []).length ); // => 3
// Extracting one by one, single emoji array
console.log( text.match(emoji_count_regex) );                // => ["","",""]
// Extracting emoji sequences
console.log( text.match(emoji_extract_or_remove_regex) );    // => [""]
// Removing emojis
console.log( text.replace(emoji_extract_or_remove_regex, '') ); // => 'flowers '
<script src="https://gitcdn.link/repo/stribizhev/Emojis/main/ws_emoji_regex.js"></script>

The emoji regex declarations are available in the https://github.com/stribizhev/Emojis/blob/main/ws_emoji_regex.js file.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • You're ECMAScript 2018+ compliant solution doesn't seem to work with '‍♂️'. It matches [ '', '♂' ]. – Maxime Dupré Jun 24 '22 at 19:02
  • 1
    @MaximeDupré Correct, I cannot even paste it as a whole Unicode character point in the console. The built-in emoji matching class is not quite safe, I only use the one built from the whole emoji list. – Wiktor Stribiżew Jun 24 '22 at 20:37
12

A simple function that returns true if your string contains one or more emojis.

function isEmoji(str) {
    var ranges = [
        '(?:[\u2700-\u27bf]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff]|[\u0023-\u0039]\ufe0f?\u20e3|\u3299|\u3297|\u303d|\u3030|\u24c2|\ud83c[\udd70-\udd71]|\ud83c[\udd7e-\udd7f]|\ud83c\udd8e|\ud83c[\udd91-\udd9a]|\ud83c[\udde6-\uddff]|[\ud83c[\ude01-\ude02]|\ud83c\ude1a|\ud83c\ude2f|[\ud83c[\ude32-\ude3a]|[\ud83c[\ude50-\ude51]|\u203c|\u2049|[\u25aa-\u25ab]|\u25b6|\u25c0|[\u25fb-\u25fe]|\u00a9|\u00ae|\u2122|\u2139|\ud83c\udc04|[\u2600-\u26FF]|\u2b05|\u2b06|\u2b07|\u2b1b|\u2b1c|\u2b50|\u2b55|\u231a|\u231b|\u2328|\u23cf|[\u23e9-\u23f3]|[\u23f8-\u23fa]|\ud83c\udccf|\u2934|\u2935|[\u2190-\u21ff])' // U+1F680 to U+1F6FF
    ];
    if (str.match(ranges.join('|'))) {
        return true;
    } else {
        return false;
    }
}
Arsen Khachaturyan
  • 7,904
  • 4
  • 42
  • 42
gidim
  • 2,314
  • 20
  • 23
8

We can detect all list of surrogate pairs or the Emoji characters in a specific range. If the issue related with storing the input string to database like MySQL version before 5.5 we need to detect and remove all the surrogate pairs using the below regex

/([\uD800-\uDBFF][\uDC00-\uDFFF])/g.
Mo.
  • 26,306
  • 36
  • 159
  • 225
RiyasAbdulla
  • 171
  • 1
  • 12
5

I wrote the following function: containsEmojis(input, includeBasic=true), which checks an input string for emojis according to the list of emojis defined in the Unicode specification version 13 (see https://unicode.org/Public/emoji/13.0/emoji-sequences.txt), and allows to ignore "basic" emojis that can be represented with only 3 bytes.

The snippet below defines the function and runs a few test cases:

/**
* iterates over the code points of an input string and returns true if an emoji is found.
* 
* an emoji is found if the hex code for the character is 5 characters starting with "1F",
* or if @includeBasic is true, the character is 4 and starts with one of the prefixes of
* a basic emoji as defined in the Unicode specification version 13 
* see https://unicode.org/Public/emoji/13.0/emoji-sequences.txt
* 
* @input the string to check
* @includeBasic include also the basic emojis that only take 3 characters
*/
function containsEmojis(input, includeBasic) {

    if (typeof includeBasic == "undefined")
        includeBasic = true;

    for (var c of input) {
        var cHex = ("" + c).codePointAt(0).toString(16);
        var lHex = cHex.length;
        if (lHex > 3) {

            var prefix = cHex.substring(0, 2);

            if (lHex == 5 && prefix == "1f") {
                return true;
            }

            if (includeBasic && lHex == 4) {
                if (["20", "21", "23", "24", "25", "26", "27", "2B", "29", "30", "32"].indexOf(prefix) > -1)
                    return true;
            }
        }
    }

    return false;
}


// can be tested as follows:
var input;
input = "Hello World!";
console.log(input, containsEmojis(input));

input = "Hello !";
console.log(input, containsEmojis(input));

console.log(input, containsEmojis(input, false));

// now try a basic emoji
input = "It sparkles ✨ yay!";
console.log(input, containsEmojis(input));

// pass false for includeBasic
console.log(input, containsEmojis(input, false));
isapir
  • 21,295
  • 13
  • 115
  • 116
5

Update for 2020: Many of these patterns don't match compound emojis or Modifier Sequences correctly, or are simply outdated and do not match the newer emojis.

Consider this kissing couple: ‍❤️‍‍. It's actually 6 (maybe more) other emojis glued together with the ZWJ zero-width joiner. To match this correctly, you have to actually match that sequence.

Thus, by matching the longer sequences first, this brute-force pattern (too long too paste, but it's a simple alternation and runs fast) correctly parses all 3521 combined emojis as of May 2021:

GitHub link: https://github.com/sweaver2112/Regex-combined-emojis

Edit 5/10/2021: If the size of the Unicode escape version of this regex is off-putting to you, you could actually skip the Unicode escape sequences and just use literal emojis, thereby saving tons of space...well, almost. This character, "*️⃣", which starts with an asterisk, will throw a "nothing to quantify" error. Getting rid of just this guy yields a much shorter, still working, copy/pastable regex that matches 3,520/3,521 Emojis at the present date:

Regex 101 Demo (compact, unsafe literal emoji version)

Regex 101 Demo (long, safe unicode escape version)

The demos' input string includes all characters from

Working example using the compact version:

/*the pattern*/
var emojiPattern = String.raw`(?:‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍||||‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍|‍❤️‍‍|‍❤️‍‍|‍❤️‍‍|‍‍‍|‍‍‍|‍‍‍|‍‍‍|‍‍‍|‍‍‍|‍‍‍|‍‍‍|‍‍‍|‍‍|‍❤️‍|‍❤️‍|‍❤️‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|‍‍|️‍️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍⚕️|‍⚕️|‍⚕️|‍⚕️|‍⚕️|‍⚕️|‍⚕️|‍⚕️|‍⚕️|‍⚕️|‍⚕️|‍⚕️|‍⚕️|‍⚕️|‍⚕️|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍⚖️|‍⚖️|‍⚖️|‍⚖️|‍⚖️|‍⚖️|‍⚖️|‍⚖️|‍⚖️|‍⚖️|‍⚖️|‍⚖️|‍⚖️|‍⚖️|‍⚖️|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍✈️|‍✈️|‍✈️|‍✈️|‍✈️|‍✈️|‍✈️|‍✈️|‍✈️|‍✈️|‍✈️|‍✈️|‍✈️|‍✈️|‍✈️|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍♂️|‍♂️|‍♂️|‍♂️|‍♂️|‍♀️|‍♀️|‍♀️|‍♀️|‍♀️|‍️|️‍♂️|️‍♀️|️‍♂️|️‍♀️|️‍♂️|️‍♀️|️‍|️‍⚧️|⛹‍♂️|⛹‍♂️|⛹‍♂️|⛹‍♂️|⛹‍♂️|⛹‍♀️|⛹‍♀️|⛹‍♀️|⛹‍♀️|⛹‍♀️|‍|‍|❤️‍|❤️‍|‍♂️|‍♀️|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍♀️|‍♂️|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍⚕️|‍⚕️|‍⚕️|‍|‍|‍|‍|‍|‍|‍⚖️|‍⚖️|‍⚖️|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍✈️|‍✈️|‍✈️|‍|‍|‍|‍|‍|‍|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍|‍|‍|‍|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍|‍|‍|‍|‍|‍|‍|‍|‍|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|⛹️‍♂️|⛹️‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍♂️|‍♀️|‍|‍|‍|‍|‍|‍❄️|‍☠️|‍⬛|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||#️⃣|0️⃣|1️⃣|2️⃣|3️⃣|4️⃣|5️⃣|6️⃣|7️⃣|8️⃣|9️⃣|✋|✋|✋|✋|✋|✌|✌|✌|✌|✌|☝|☝|☝|☝|☝|✊|✊|✊|✊|✊|✍|✍|✍|✍|✍|⛹|⛹|⛹|⛹|⛹||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||☺|☹|☠|❣|❤|✋|✌|☝|✊|✍|⛷|⛹|☘|☕|⛰|⛪|⛩|⛲|⛺|♨|⛽|⚓|⛵|⛴|✈|⌛|⏳|⌚|⏰|⏱|⏲|☀|⭐|☁|⛅|⛈|☂|☔|⛱|⚡|❄|☃|⛄|☄|✨|⚽|⚾|⛳|⛸|♠|♥|♦|♣|♟|⛑|☎|⌨|✉|✏|✒|✂|⛏|⚒|⚔|⚙|⚖|⛓|⚗|⚰|⚱|♿|⚠|⛔|☢|☣|⬆|↗|➡|↘|⬇|↙|⬅|↖|↕|↔|↩|↪|⤴|⤵|⚛|✡|☸|☯|✝|☦|☪|☮|♈|♉|♊|♋|♌|♍|♎|♏|♐|♑|♒|♓|⛎|▶|⏩|⏭|⏯|◀|⏪|⏮|⏫|⏬|⏸|⏹|⏺|⏏|♀|♂|⚧|✖|➕|➖|➗|♾|‼|⁉|❓|❔|❕|❗|〰|⚕|♻|⚜|⭕|✅|☑|✔|❌|❎|➰|➿|〽|✳|✴|❇|©|®|™|ℹ|Ⓜ|㊗|㊙|⚫|⚪|⬛|⬜|◼|◻|◾|◽|▪|▫)`

/*compile the pattern string into a regex*/
let emoRegex = new RegExp(emojiPattern, "g")

/*extracting the emojis*/
let emojis = [..."This ‍⚖️is the ‍♀️text‍❤️‍‍.".matchAll(emoRegex)];
console.log(emojis)

/*count of emojis*/
let emoCount = [..."This ‍⚖️is the ‍♀️text‍❤️‍‍.".matchAll(emoRegex)].length
console.log(emoCount)

/*strip emojis from text*/
let stripped = "This ‍⚖️is the ‍♀️text‍❤️‍‍.".replaceAll(emoRegex, "")
console.log(stripped)

/*use the pattern string to build a custom regex*/
let customRegex = new RegExp(".*"+emojiPattern+"{3}$") //match a string ending in 3 emojis
console.log(customRegex.test("yep three here ‍⚖️‍❤️‍‍")) //true
console.log(customRegex.test("nope ‍❤️‍‍")) //false
Scott Weaver
  • 7,192
  • 2
  • 31
  • 43
4

You can use regular expression to detect it in input text:

/([\uE000-\uF8FF]|\uD83C[\uDF00-\uDFFF]|\uD83D[\uDC00-\uDDFF])/g
andorx
  • 339
  • 1
  • 6
  • 3
    does not match all emojis `/^([\uE000-\uF8FF]|\uD83C[\uDF00-\uDFFF]|\uD83D[\uDC00-\uDDFF])+$/.test("") // false` – sritmak May 24 '17 at 13:18
1

another solution I found that worked for me:

const example = '‍‍‍';
const regexpEmojiPresentation = /\p{Emoji_Presentation}/gu;
console.log(example.match(regexpEmojiPresentation));
1

Answer

According with the Unicode Standard 15.0 docs. (EBNF and Regex):

Emojis Regex Shape

\p{RI} \p{RI} 
| \p{Emoji} 
  ( \p{EMod} 
  | \x{FE0F} \x{20E3}? 
  | [\x{E0020}-\x{E007E}]+ \x{E007F}
  )?
  (\x{200D}
    ( \p{RI} \p{RI}
    | \p{Emoji}
      ( \p{EMod} 
      | \x{FE0F} \x{20E3}? 
      | [\x{E0020}-\x{E007E}]+ \x{E007F}
      )?
    )
  )*

Emojis Regex in JavaScript

const emojisRegex = /\p{RI}\p{RI}|\p{Emoji}(\p{EMod}|\uFE0F\u20E3?|[\u{E0020}-\u{E007E}]+\u{E007F})?(\u200D(\p{RI}\p{RI}|\p{Emoji}(\p{EMod}|\uFE0F\u20E3?|[\u{E0020}-\u{E007E}]+\u{E007F})?))*/gu;

Almost the same including flags g for global and u for extended unicode escapes.

Keeping #*0123456789©® Out of the Formula

Characters #*0123456789©® are the only ones from ASCII and ASCII Supplement that match as emojis. You don't need to worry about the following subsets: CJK Unified Ideographs (Han), Hiragana, Kangxi Radicals, and Katakana; not a single one matches.

In case you need to exclude the ones mentioned before, you could filter them.

// E.g.:
const emojisRegex = /\p{RI}\p{RI}|\p{Emoji}(\p{EMod}|\uFE0F\u20E3?|[\u{E0020}-\u{E007E}]+\u{E007F})?(\u200D(\p{RI}\p{RI}|\p{Emoji}(\p{EMod}|\uFE0F\u20E3?|[\u{E0020}-\u{E007E}]+\u{E007F})?))*/gu;
const input = '#*Aa01©®ぁあァア⿔⿕✔✔️3️⃣‍❤️‍';
input
  .match(emojisRegex)
  .filter(emoji => !/^[#*0-9©®]$/.test(emoji));
// ['✔', '✔️', '3️⃣', '', '‍❤️‍']

Note About the Top Rated Anwer

Regex \p{Emoji} will not do the job in case you need to identify and isolate each emoji. It matches the smallest portion of emojis, that means, the vast majority of results will look like broken emojis, even the oldest, simplest ones will be modified.

// E.g.:
const vagueRegex = /\p{Emoji}/gu;
const emojisRegex = /\p{RI}\p{RI}|\p{Emoji}(\p{EMod}|\uFE0F\u20E3?|[\u{E0020}-\u{E007E}]+\u{E007F})?(\u200D(\p{RI}\p{RI}|\p{Emoji}(\p{EMod}|\uFE0F\u20E3?|[\u{E0020}-\u{E007E}]+\u{E007F})?))*/gu;

'✔✔️3️⃣‍❤️‍'.match(vagueRegex);  // ['✔', '✔', '3', '', '', '', '', '❤', '', '']
'✔✔️3️⃣‍❤️‍'.match(emojisRegex); // ['✔', '✔️', '3️⃣', '', '‍❤️‍']
Leo
  • 849
  • 7
  • 20
-1

check the emoji like bellow ways

function getEmojiChars(text) {

console.log(text.match(/\ud83c[\udf00-\udfff]|\ud83d[\udc00-\ude4f]|\ud83d[\ude80-\udeff]/g))  ;
}

you will get the array of emoji in the text