1

I don't know any about emoji characters unicode and trying to remove all emoji from input, found a code:

var ranges = [
  '\ud83c[\udf00-\udfff]', // U+1F300 to U+1F3FF
  '\ud83d[\udc00-\ude4f]', // U+1F400 to U+1F64F
  '\ud83d[\ude80-\udeff]'  // U+1F680 to U+1F6FF
];

JSFiddle (copy emojis from css section to test)

it will remove some but not new emojis. how can include these new emojis unicode range to this code?

for example this won't remove nerd face emoji, and the unicode is here

1 Answers1

0
function removeEmoji(text) {
  var res = '';

  for(var i = 0; i < text.length; i++) {
    var c = text[i];

    // Get UTF-32 code
    var code = c.charCodeAt(0);
    if(code >= 0xd800 && code < 0xdc00) {
      c += text[++i];
      code = (code - 0xd800) << 10;
      code |= c.charCodeAt(1) - 0xdc00;
      code += 0x10000;
    }

    // Skip Emoji symbols
    if (code < 0x1f000 || code >= 0x1fa00) {
      res += c;
    }
  }

  return res
}

var s = removeEmoji('ab'); // 'ab'
Artem
  • 1,773
  • 12
  • 30