public static void main(String[] args) {
String strContent="请到以下地址查询:查询地址:充值地址:https://pay.sdo.com/Index.aspx?type=card尊敬的用户: 您好,该卡帐号和密码是正确的,请到以下https://pay.sdo.com/Index.aspx?type=card 地址查询:查询地址:充值地址:https://pay.sdo.com/Index.aspx?type=card ";
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);
replace.append("\" target=\"_blank\">"+urlStr+"</a>");
matcher.appendReplacement(result, replace.toString());
}
matcher.appendTail(result);
System.out.println(result);
}
java获取一段文字的url地址并以链接的形式显示在网页上
最新推荐文章于 2022-06-01 16:05:03 发布