String title = "HD_爸爸,\玛丽和我".replaceAll("\", "");
我要替换这里面去掉这里面的\
报错:Exception in thread "main" java.util.regex.PatternSyntaxException: Unexpected internal error near index 1
\
^ 怎么解决?
java 替换 \ 的出错?????
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
2条回答 默认 最新
_1_1_7_ 2012-09-04 14:40关注[code="java"] static final Pattern pattern=Pattern.compile("\\");
public static void main(String[] args) throws Exception {
String s = "HD_爸爸,\玛丽和我";
String s1 = s.replaceAll("\\", "");
String s2 = s.replace('\', ' ');
System.out.println(s1);
System.out.println(s2);//多次调用时,用以下方式性能更好 Matcher m=pattern.matcher(s); String s3=m.replaceAll(""); System.out.println(s3); }[/code]本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报