首页 > 编程语言 > 详细

特殊字符导致用正则表达式进行字符串替换失败,Java replaceAll()方法报错Illegal group reference

时间:2015-10-05 16:55:04      阅读:596      评论:0      收藏:0      [点我收藏+]

 

 

String str = "给商品||?>\\n阳澄湖大闸蟹!@#$%^&*()_+-=?:\",.]\\|~.,\/??\\\\|\\br点赞"
1 String tradeDescription = "||?>\\n阳澄湖大闸蟹!@#$%^";
2 String description = "给商品 #goodsName# 点赞";
3 String result = description.replaceAll("#goodsName#", Matcher.quoteReplacement(CommonUtil.toString(tradeDescription)));

 

 

 

参考:

 

http://www.colabug.com/thread-1131948-1-1.html

特殊字符导致用正则表达式进行字符串替换失败,Java replaceAll()方法报错Illegal group reference

原文:http://www.cnblogs.com/xunux/p/4855860.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!