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

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

参考:

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

上一篇:1z0-052 q209_5


下一篇:【转】Android新组件Material Dialog,SwipeRefreshLayout,ListPopupWindow,PopupMenu等