判断字符串中是否含有Emoji表情并去除
- 查询数据库异常,说字符集异常
原因:是数据库的字符集使用的是 utf-8 mb4 - 解决办法:去除Emoji表情
/**
判断字符串是否含有Emoji表情
**/
private boolean isHasEmoji(String reviewerName) {
Pattern pattern = Pattern.compile("[\ud83c\udc00-\ud83c\udfff]|[\ud83d\udc00-\ud83d\udfff]|[\u2600-\u27ff]");
Matcher matcher = pattern.matcher(reviewerName);
return matcher.find();
}
String reviewerName = "???????8888";
String replaceAll = reviewerName.replaceAll("[\\ud800\\udc00-\\udbff\\udfff\\ud800-\\udfff]", "");
System.out.println("repalceAll"+replaceAll);