Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Regex to match all unicode Emojis? [duplicate]

I need a Regex to match all unicode emojis. I need this to check if a discord message has a Unicode Emoji in it.

// Here is a example of matching one Unicode Emoji
message.content.match(/😊/g)
// or two
message.content.match(/😇|😊/g)
// and three
message.content.match(/😇|😊|😈/g)
// then so on.

I have gotten up to like the last 300 or so emojis with this method then it stops working, sending all kinds of errors and stuff.

Is there a better way to do this? and if there is then can you give me an example in the comments. Im new to coding and don't really understand regex and some other stuff so having an example would help a lot. Also I code in JavaScript with node.js on Visual Studio Code.

UPDATE: there is a way that does work and i'm so grateful to Lioness100 for telling about it. There is a npm package called Emoji-Regex. Very useful!

like image 883
MIMJA156 Avatar asked Dec 14 '25 00:12

MIMJA156


2 Answers

You can use this Regex to match all emojis:

/(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])/g

You can test it here on a full list of emojis: https://regex101.com/r/0anB6Z/1

Beware, this will also match currencies symbols (€, $, £...), mathematical signs and some punctuation signs, as well as Japanese characters. If you want a less strict match, you can remove the first range.

Less strict match:

/(\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])/g
like image 52
pimarc Avatar answered Dec 15 '25 13:12

pimarc


For anyone interested, I spent some time and collected complete regular expression based off of emoji standard:

https://gist.github.com/Saluev/604c9c3a3d6032770e15a0da143f73bd

For parsing single emoji, use either

re.match(EMOJI_SEQUENCE, string)
# or
EMOJI_REGEXP.match(string)

To match multiple emojis or custom patterns, insert EMOJI_SEQUENCE into pattern:

re.match(rf"{EMOJI_SEQUENCE}+\s*...", string)
like image 34
Tigran Saluev Avatar answered Dec 15 '25 14:12

Tigran Saluev