Regular expression for capturing all skin-tone variations of an emoji

喜欢而已 提交于 2019-12-11 09:56:09

问题


I'm trying to use a regex to capture tweets containing the substring 👏 at least twice, so I'm using an unsophisticated ^.+ 👏 .+ 👏 .+$. However this doesn't match strings which instead contain, for example, 👏🏼.

Is there a smart way I can capture an emoji with any or none skin-tone variation, without just putting each one in a row (like [👏👏🏻👏🏼👏🏽👏🏾👏🏿])?


回答1:


Thanks to comments above, I've found that emojis I've encountered on twitter are unicode, and skin-tone variations are combining characters in the range 1f3fb1f3ff.

http://unicode.org/reports/tr51/#Emoji_Modifiers_Table

So for me what I wanted was 👏[\x{1f3fb}-\x{1f3ff}]?, with [\x{1f3fb}-\x{1f3ff}]? being something I can then drop next to any unmodified emoji to include skin-tone variations.



来源:https://stackoverflow.com/questions/36331572/regular-expression-for-capturing-all-skin-tone-variations-of-an-emoji

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!