问题描述
- There is some exceptions in 'XmlUtil.getRegex' : 替换所有的注释字符
- java.util.regex.PatternSyntaxException: Unclosed group near index 77
<!-- servlets with servlet mappings (defined either here or in your own -->
String ss = "dddd(java)hello";
//下面就会报错
System.out.println(ss.replaceAll("(java)", ""));
改为
String ss = "dddd(java)hello";
//正解
System.out.println(ss.replaceAll("\\(java)", ""));
- There is some exceptions in 'XmlUtil.getRegex' : 替换所有的注释字符
- java.util.regex.PatternSyntaxException: Unclosed group near index 77
<!-- servlets with servlet mappings (defined either here or in your own -->
String ss = "dddd(java)hello";
//下面就会报错
System.out.println(ss.replaceAll("(java)", ""));
改为
String ss = "dddd(java)hello";
//正解
System.out.println(ss.replaceAll("\\(java)", ""));
本文介绍了一个在Java中使用正则表达式替换字符串中的注释字符时遇到的PatternSyntaxException问题,并提供了解决方案。通过在正则表达式中添加转义字符,成功解决了错误。

1086

被折叠的 条评论
为什么被折叠?



