2

Hey so I need to create a script using googlespreadsheets (javascript) that takes the input of one cell and outputs all the emojis from that cell into the selected one. I want to do this by removing everything from the cell text except the emoji. This is because if I try to just match emojis my output is not correct.

I'm using this regex to locate emojis.

  var re = /[\u1F60-\u1F64]|[\u2702-\u27B0]|[\u1F68-\u1F6C]|[\u1F30-\u1F70]|[\u2600-\u26ff]|[\uD83C-\uDBFF\uDC00-\uDFFF]+/gi;

How can I remove everything from the text except items with this regex. Or how can I remove everything but unicode. I have tried all the other suggestions but the output isn't correct or it doesn't work with spreadsheets.

Currently I have:

function SHOW_EMOJIS(s) {
   var re = /[\u1F60-\u1F64]|[\u2702-\u27B0]|[\u1F68-\u1F6C]|[\u1F30-\u1F70]|[\u2600-\u26ff]|[\uD83C-\uDBFF\uDC00-\uDFFF]+/gi;
   var result = s.match(re).toString();

   return result;
}

This returns all the emojis, but instead of seeing: ⚠️❄️‍⚕️☃️ I see ⚠,,❄,,⚕,☃, . The doctor is returned as two separate emoji-characters.

TheMaster
  • 45,448
  • 6
  • 62
  • 85
imapotatoe123
  • 656
  • 1
  • 10
  • 21

2 Answers2

4

Instead of a custom function, Why not try the inbuilt REGEX?

=REGEXREPLACE(A5,"[[:print:]]","")

Emoji is not printable according to Google Re2

TheMaster
  • 45,448
  • 6
  • 62
  • 85
0

To replace all emojis from [A1] please try:

=REGEXREPLACE($A$1,"[©®‼⁉™ℹ↔-↙↩-↪⌚-⌛⌨⏏⏩-⏳⏸-⏺Ⓜ▪-▫▶◀◻-◾☀-☄☎☑☔-☕☘☝☠☢-☣☦☪☮-☯☸-☺♀♂♈-♓♟-♠♣♥-♦♨♻♾-♿⚒-⚗⚙⚛-⚜⚠-⚡⚧⚪-⚫⚰-⚱⚽-⚾⛄-⛅⛈⛎-⛏⛑⛓-⛔⛩-⛪⛰-⛵⛷-⛺⛽✂✅✈-✍✏✒✔✖✝✡✨✳-✴❄❇❌❎❓-❕❗❣-❤➕-➗➡➰➿⤴-⤵⬅-⬇⬛-⬜⭐⭕〰〽㊗㊙-----------------------------------------------#️⃣*️⃣0️⃣1️⃣2️⃣3️⃣4️⃣5️⃣6️⃣7️⃣8️⃣9️⃣]","")

Related Answer:

https://stackoverflow.com/a/70125203/5372400


=REGEXREPLACE(A5,"[[:print:]]","") is a nice solution, but have some drawbacks:

  • it leaves these chars: 0 1 2 3 4 5 6 7 8 9 # * on the place of respective emojis 0️⃣ 1️⃣ 2️⃣ 3️⃣ 4️⃣ 5️⃣ 6️⃣ 7️⃣ 8️⃣ 9️⃣ #️⃣ *️⃣
  • it also replaces other not printable chars.

Test sheet

Max Makhrov
  • 17,309
  • 5
  • 55
  • 81