javascript unicode emoji regular expressions

前端 未结 4 2161
無奈伤痛
無奈伤痛 2020-11-30 09:04

i want to replace all emoji in string with icon now i successfully replaced those {:) :D :P :3 <3 XP .... etc} to icon so if user write :) thi

4条回答
  •  既然无缘
    2020-11-30 09:46

    Note - The below regex will match surrogate pairs (Supplemental), as well as single (Basic).

    To see the hex version of what matched:
    If the length of the match is 2, character 1 is a low surrogate, character 2 is a high surrogate. Just format each character to hex, and join them in a string.

    You could try to match some emoji via hex ranges.

    This regex matches these 1,114 emoji characters.

    Note - this excludes characters in the range \x00-\x7f; for some reason there are emoji in this range like 0-9.. (using \p{Emoji=yes}).

    The below regex will match these emoji.

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

提交回复
热议问题