Java字符串中的emoji过滤

注意单斜杠不要双斜杠,否则无法正确匹配

public static void main(String[] args) {

        String content="\ud83c\udc02\ud83d\udc02\u2600-\u27ff";
        System.out.println(content);
        System.out.println("emoji:"+hasEmoji(content));
    }
    
    public static boolean hasEmoji(String content){
        Pattern pattern = Pattern.compile("[\ud83c\udc00-\ud83c\udfff]|[\ud83d\udc00-\ud83d\udfff]|[\u2600-\u27ff]");
        Matcher matcher = pattern.matcher(content);
        if(matcher .find()){
            return true;    
        }
        return false;
    }

猜你喜欢

转载自blog.csdn.net/u013045102/article/details/80983150