Check if emoji character [duplicate]

青春壹個敷衍的年華 提交于 2019-12-10 11:57:50

问题


I have a Java servlet which accepts text from mobile devices. I need to check each character and check if it is a normal text or if it is an emoji before I insert it into my database. The problem I am having is how do I detect if a character is emoji?


回答1:


ok simple example defined private string emoji regex.

 private final String regex = "([\\u20a0-\\u32ff\\ud83c\\udc00-\\ud83d\\udeff\\udbb9\\udce5-\\udbb9\\udcee])";

variable with test sentence

test = "josh stevens is the best 😂"

you can use a Matcher to find any group in the test string that matches the regex.

Matcher matchEmo = Pattern.compile(regex).matcher(test);
while (matchEmo.find()) {
    System.out.println(matchEmo.group());
}

this will print the emoji which matches them in string. Hope this helps.



来源:https://stackoverflow.com/questions/30767631/check-if-emoji-character

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