String regex = "(http:|https:)//[^[A-Za-z0-9\\._\\?%&+\\-=/#]]*"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(strContent); StringBuffer result = new StringBuffer(); while (matcher.find()) { String urlStr = matcher.group(); StringBuffer replace = new StringBuffer(); replace.append("<a href="\"").append(urlStr);" target="\"_blank\"">"+urlStr+"</a>"); matcher.appendReplacement(result, replace.toString()); } matcher.appendTail(result); System.out.println(result);栖息邦 收藏Ctrl+D 转载注明来源
给非a标签外部链接加上跳转
Pre: WordPress 标题链接到站外链接
Next: 自定义WordPress评论Cookie功能
您可能感兴趣的文章
- 纯代码实现,每个IP每天或者每小时弹窗/跳转一次 - 2017-10-8 周日
- 2021 RSSHub 订阅源 - 2022-1-22 周六
- 搞定WordPress小工具分类文章 - 2019-5-5 周日
- 围棋第29届LG杯第三局柯洁再次犯规,告负
- 多仓多线路影视应用及接口随便睇