java过滤emoji表情

由于在做搜索的时候emoji的表情并不需要,所以需要过滤掉

import java.util.regex.Matcher;
import java.util.regex.Pattern;
 
public class EmojiFilter implements Filter {
 
    @Override
    public  String filter(String str) {
        
        if(str.trim().isEmpty()){
            return str;
        }
        String pattern="[\ud83c\udc00-\ud83c\udfff]|[\ud83d\udc00-\ud83d\udfff]|[\u2600-\u27ff]";
        String reStr="";
        Pattern emoji=Pattern.compile(pattern);
        Matcher  emojiMatcher=emoji.matcher(str);
        str=emojiMatcher.replaceAll(reStr);
        return str;
    }
 
}

标签: none

添加新评论