/**
* 过滤 “�”(任意0-7位数字)格式的特殊字符(过滤范围�-一 & 龥-�)(中文范围 一 - 龥)
* @param str
* @return
*/
public static String filter(String str) {
if (str == null || str.length() == 0) {
return str;
}
String regEx = "&#([1-9]\\d{0,3});|&#(1[0-9]\\d{3});|&#(19[0-9]\\d{2});|&#(199[0-6]\\d);|&#(1996[0-8]);";
//匹配范围 龥-�
String regEx2 = "|&#(409\\d{2});|&#(40[0-8]\\d{2});|&#(4[0-8]\\d{3});|&#([5-9]\\d{4});|&#(\\d{6});|&#(\\d{7});";
String regEx3 = regEx + regEx2;
// String str = "����顾客代理们��三月一日微信转账收费啦��";
Pattern pat = Pattern.compile(regEx3);
Matcher mat = pat.matcher(str);
boolean isMatcher = mat.find();
if (isMatcher){
try {
str = str.replaceAll(mat.group(0), "");
} catch (Exception e) {
// TODO: handle exception
}
}
while (mat.find()) {
str = str.replaceAll(mat.group(0), "");
}
return str;
}
* 过滤 “�”(任意0-7位数字)格式的特殊字符(过滤范围�-一 & 龥-�)(中文范围 一 - 龥)
* @param str
* @return
*/
public static String filter(String str) {
if (str == null || str.length() == 0) {
return str;
}
String regEx = "&#([1-9]\\d{0,3});|&#(1[0-9]\\d{3});|&#(19[0-9]\\d{2});|&#(199[0-6]\\d);|&#(1996[0-8]);";
//匹配范围 龥-�
String regEx2 = "|&#(409\\d{2});|&#(40[0-8]\\d{2});|&#(4[0-8]\\d{3});|&#([5-9]\\d{4});|&#(\\d{6});|&#(\\d{7});";
String regEx3 = regEx + regEx2;
// String str = "����顾客代理们��三月一日微信转账收费啦��";
Pattern pat = Pattern.compile(regEx3);
Matcher mat = pat.matcher(str);
boolean isMatcher = mat.find();
if (isMatcher){
try {
str = str.replaceAll(mat.group(0), "");
} catch (Exception e) {
// TODO: handle exception
}
}
while (mat.find()) {
str = str.replaceAll(mat.group(0), "");
}
return str;
}