表情符号过滤



public class EmojiFilter {
/**
* 过滤emoji 或者 其他非文字类型的字符

* @param source 需要被过滤的字符串
* @return
*/
public static String filterEmoji(Object source) {
String sourceStr = " ";//针对微信传递过来的值为空数据时,默认为空字符串
if(Toolkit.isEmpty(source)){
return sourceStr;
}

Pattern emoji = Pattern.compile("[\ud83c\udc00-\ud83c\udfff]|[\ud83d\udc00-\ud83d\udfff]|[\u2600-\u27ff]",
Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE);
Matcher emojiMatcher = emoji.matcher(sourceStr);
if (emojiMatcher.find()) {
source = emojiMatcher.replaceAll("");
return sourceStr;
}

return sourceStr;
}

你可能感兴趣的:(表情符号过滤)