本文主要是介绍切割字符串错误: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"));
这篇关于切割字符串错误:Unclosed character class near index 0 [ ^ 转义符问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!