美文网首页
使用正则表示过滤表情符号

使用正则表示过滤表情符号

作者: 宝贝双双 | 来源:发表于2017-06-07 18:19 被阅读0次

/**

* 过滤表情符号

* @create by ldw on 2016-10-25

* @param str

* @return str(去掉表情符号的字符串)

* @version 1.0

* */

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;

}

//亲自试过,管用

相关文章

网友评论

      本文标题:使用正则表示过滤表情符号

      本文链接:https://www.haomeiwen.com/subject/sgsafxtx.html