Java 特殊字符正则替换

Posted lshan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java 特殊字符正则替换相关的知识,希望对你有一定的参考价值。

 

 

    @Test
    public void testRegex() throws Exception {
                String str="das:! $%#*(*(";
                String regEx = "[`~!@#$%^&*()+=|{}‘:;‘\[\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]|
|
|	";
                Pattern p = Pattern.compile(regEx);
                Matcher m = p.matcher(str);
                boolean isfind = m.find();
                System.err.println(isfind);
                 //regex 
                String replaceAll = str.replaceAll(regEx, "");
                 System.out.println(replaceAll);
     }

 

以上是关于Java 特殊字符正则替换的主要内容,如果未能解决你的问题,请参考以下文章