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

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

发表评论

表情:
评论列表 (有 0 条评论,123人围观)

还没有评论,来说两句吧...

相关阅读