正则匹配可以与肤色修饰符有效结合的表情符号?
检测表情符号的JS代码(从通常的意义上讲,“表情符号”)简直就是:
let str = "...";
if(/\p{Extended_Pictographic}/u.test(str)) {
// do something
}
是否有一些等效的方法来检测表情符号可以有效地添加给它们的肤色修饰符?
关键要求是,随着添加更多的表情符号或现有表情符号,我不必在多年来更新正则是肤色。基本上,我想知道是否有类似skin
Unicode属性逃脱的东西,或者其他一些优雅和未来的范围解决方案。
注意:
- 它必须无需DOM访问就可以工作(即服务器端,工人等)。
- 请注意,目标不是 检测肤色修饰符,而是检测可以有效添加肤色修饰符的表情符号 - 例如,REGEX/功能应匹配
(没有肤色修饰符,但是在其中添加一个是有效的)。
- 我想强调的是,一个不符合未来的不适合我特殊用例的要求的大型不适合未来的不符合条件。但是请注意,如果,一堆Unicode范围确实符合要求,这是将来的证明。
- 这个问题在考虑时似乎是相似的标题,但是在阅读问题的正文后,它问了一个不同的问题。
The JS code to detect emojis (in the usual sense of the term "emoji") is simply:
let str = "...";
if(/\p{Extended_Pictographic}/u.test(str)) {
// do something
}
Is there some equivalently simple way to detect emojis that can have skin tone modifiers validly added to them?
A key requirement is that I don't have to update the regex over the years as more emojis are added, or existing emojis become skin-tone-able. Basically I'm wondering if there's something like a Skin
Unicode property escape, or some other elegant and future-proof solution.
Notes:
- It must work without DOM access (i.e. server-side, workers, etc.).
- Note that the goal is not to detect skin tone modifiers, but to detect emojis that can validly have a skin tone modifier added to it - e.g. the regex/function should match
????
(doesn't have skin tone modifier, but it is valid to add one to it). - I want to emphasise that a big-old-bunch-of-unicode-ranges regex that's not future-proof does not fit the requirements of my particular use case. But note that a bunch of Unicode ranges does fit the requirements if it's future proof.
- This question appears to be similar when considering the title, but upon reading the body of the question, it's asking a different question.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 fitzpatrick scale 以检测出肤色的emoji。具有肤色的表情符号将包含六个fitzpatrick秤中的任何一个。
编辑:
此解决方案使用元素。getBoundingClientRect()来确定表情符号在加入Fitzpatrick肤色表情符号后是否具有相同的宽度和高度。
You can use Fitzpatrick scale to detect a skin-toned emoji. An emoji with a skin tone will contain any one of the six Fitzpatrick scale unicodes.
EDIT:
This solution uses Element.getBoundingClientRect() to determine whether an emoji will have the same width and height after having concatenated the Fitzpatrick skin tone emoji.
相关的Unicode字符属性称为
emoji_modifier_base
。/\ p {emoji_modifier_base}/u.test()
将返回每个表情符号字符的true。The relevant Unicode character property is called
Emoji_Modifier_Base
./\p{Emoji_Modifier_Base}/u.test()
will return true for every emoji character that can take a skin tone modifier.