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

时间:2016-10-16 00:50:02   收藏:0   阅读:3111
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

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!