JN项目-查询条件过滤特殊字符

来源:互联网 发布:js date对象 编辑:程序博客网 时间:2024/05/18 18:00


public static String StringFilter(String str) throws PatternSyntaxException {// 只允许字母和数字 // String regEx ="[^a-zA-Z0-9]";// 清除掉所有特殊字符String regEx = "[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]";Pattern p = Pattern.compile(regEx);Matcher m = p.matcher(str);return m.replaceAll("").trim();}