run_wind

导航

捕获链接文字的简单正则

注:本文转载于: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));
}

posted on 2012-11-20 14:28  run_wind  阅读(109)  评论(0编辑  收藏  举报