最近写的一个过滤特殊字符的方法
- //过滤特殊字符
- publicStringStringFilter(Stringstr)throwsPatternSyntaxException{
- //只允许字母和数字
- //StringregEx="[^a-zA-Z0-9]";
- //清除掉所有特殊字符
- StringregEx="[`~!#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】\"‘;:”“’。,、?]";
- Patternp=Pattern.compile(regEx);
- Matcherm=p.matcher(str);
- returnm.replaceAll("").trim();
- }