java使用正则表达式过滤特殊字符
/**
* @Author: Hyy
* @Desc: 正则表达式过滤字符
* @Date: 2021/9/28 20:56
*/
public class CharacterFilter {
/**
* 过滤出中文、数字、字母
* @param str
* @return
*/
public static String stringFilter(String str) {
return str.replaceAll("[^(a-zA-Z0-9\\\\u4e00-\\\\u9fa5)]","").trim();
}
/**
* 过滤出中文
* @param str
* @return
*/
public static String chineseFilter(String str) {
return str.replaceAll("[^(\\u4e00-\\u9fa5)]","").trim();
}
/**
* 过滤出数字
* @param str
* @return
*/
public static String numberFilter(String str) {
return str.replaceAll("[^0-9]","").trim();
}
}