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);
给非a标签外部链接加上跳转
Pre: WordPress 标题链接到站外链接
Next: 自定义WordPress评论Cookie功能
- 纯代码实现,每个IP每天或者每小时弹窗/跳转一次 - 2017-10-8 周日
- wordpress文章内点击图片进入下一页 - 2017-9-20 周三
- 纯代码给WordPress后台添加显示用户注册时间和登录 IP 记录 - 2023-1-16 周一
- WordPress付费查看阅读插件:WPPAY永久版
- 多仓多线路影视应用及接口随便睇