f9538e62c31826c5c2677b2b050b36fe2dc16d31.svn-base 809 B

123456789101112131415161718192021222324
  1. package org.jeecg.common.util.filter;
  2. import java.util.regex.Matcher;
  3. import java.util.regex.Pattern;
  4. import java.util.regex.PatternSyntaxException;
  5. /**
  6. * 文件上传字符串过滤特殊字符
  7. */
  8. public class StrAttackFilter {
  9. public static String filter(String str) throws PatternSyntaxException {
  10. // 清除掉所有特殊字符
  11. String regEx = "[`_《》~!@#$%^&*()+=|{}':;',\\[\\].<>?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]";
  12. Pattern p = Pattern.compile(regEx);
  13. Matcher m = p.matcher(str);
  14. return m.replaceAll("").trim();
  15. }
  16. // public static void main(String[] args) {
  17. // String filter = filter("@#jeecg/《》【bo】¥%……&*(o))))!@t<>,.,/?'\'~~`");
  18. // System.out.println(filter);
  19. // }
  20. }