Exception in thread "main" java.util.regex.PatternSyntaxException: Unclosed character class near index 0 [ ^

Exception in thread "main" java.util.regex.PatternSyntaxException: Unclosed character class near index 0 [ ^

出现此错误应该是字符转义出现问题:

System.out.println(str.replaceAll("[", "22"));
解决方案:在[之前加上\\
System.out.println(str.replaceAll("\\[", "22"));
文章来自:http://www.cnblogs.com/wangchaoyuan/p/5965460.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3