Exception in thread "main" java.util.regex.PatternSyntaxException: Unclosed character clas

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Exception in thread "main" java.util.regex.PatternSyntaxException: Unclosed character clas相关的知识,希望对你有一定的参考价值。

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"));

以上是关于Exception in thread "main" java.util.regex.PatternSyntaxException: Unclosed character clas的主要内容,如果未能解决你的问题,请参考以下文章

Exception in thread "main" java.lang.UnsupportedClassVersionError

Exception in thread "main" java.util.InputMismatchException

Exception in thread "main" java.lang.ClassCastException

Exception in thread "main" java.lang.UnsatisfiedLinkError:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1

Exception in thread "main" java.lang.NullPointerException