java去除非法字符

来源:互联网 发布:游开服表数据 编辑:程序博客网 时间:2024/04/30 02:13
/** * 过滤非法字符 */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();     }

原创粉丝点击