Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is this lib basically doing /\p{Emoji}|\p{Default_Ignorable_Code_Point}/gu ? #104

Closed
caub opened this issue Nov 19, 2022 · 3 comments
Closed

Comments

@caub
Copy link

caub commented Nov 19, 2022

That regex /\p{Emoji}|\p{Default_Ignorable_Code_Point}/ would detect all emojis and join controls

@caub caub changed the title Is this lib basically doing /\p{Emoji}|\p{Default_Ignorable_Code_Point}/ ? Is this lib basically doing /\p{Emoji}|\p{Default_Ignorable_Code_Point}/gu ? Nov 19, 2022
@mathiasbynens
Copy link
Owner

Is this lib basically doing /\p{Emoji}|\p{Default_Ignorable_Code_Point}/gu?

No.

\p{Emoji} only matches emoji consisting of a single code point. The vast majority of emoji consist of multiple code points.

We use https://github.com/mathiasbynens/emoji-test-regex-pattern.

@caub
Copy link
Author

caub commented Nov 19, 2022

In my usecase, I just need to remove them, so I can do

'️🤷‍♂️'.replace(/\p{Emoji}|\p{Default_Ignorable_Code_Point}/gu, '').length
0

and that works for multi code points emojis is this right?

but .match(/\p{Emoji}|\p{Default_Ignorable_Code_Point}/gu) return multiple characters instead of one, is this what you mean?

@mathiasbynens
Copy link
Owner

It might work for some of them, but certainly not for all. Testing it against the full list in https://github.com/mathiasbynens/emoji-test-regex-pattern/blob/main/dist/latest/index-strings.txt, there are several failures.

// Note: `string` is the contents of the text file I pointed to.
string.replace(/\p{Emoji}|\p{Default_Ignorable_Code_Point}/gu, '').replaceAll('\n', '').length;
// -> 84
[...string.replace(/\p{Emoji}|\p{Default_Ignorable_Code_Point}/gu, '').replaceAll('\n', '')].length;
// -> 54

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants