java过滤特殊字符

来源:互联网 发布:淘宝客服应聘面试技巧 编辑:程序博客网 时间:2024/04/28 08:05

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();     
    }

http://sunlianwei.javaeye.com/blog/363759