捕获链接文字的简单正则
注:本文转载于:http://blog.sina.com.cn/s/blog_600ff07501014lgb.html
Pattern pattern = Pattern.compile("<(\\S+?)\\s+(?:\"[^\"]*\"|'[^']*'|[^\"'><])+>(.+?)</\\1>");
Matcher matcher = pattern.matcher("<a href=\"http://baidu.com\">这是连接文字 </a><a onclick=\"alert(1)\" href=\"http://baidu.com\">这是连接文字2</a>");
while(matcher.find()) {
if(matcher.groupCount() > 1)
System.out.println(matcher.group(2));
}
浙公网安备 33010602011771号