Pattern p = Pattern.compile("<a\\s+href\\s*=\\s*(\"|\‘)?(.*?)[\"|\‘|>]", Pattern.CASE_INSENSITIVE); Matcher m = p.matcher("<div class=\"related-tags\">\n" + " <span>相关主题推荐:</span>\n" + " <a href=\‘http://www.csdn.net/tag/标签\‘ target=\"_blank\">标签</a>\n" + " <a href=\"http://www.csdn.net/tag/java\" target=\"_blank\">java</a>\n" + " <a href=\"http://www.csdn.net/tag/团购\" target=\"_blank\">团购</a>\n" + " <a href=\"http://www.csdn.net/tag/体育\" target=\"_blank\">体育</a>\n" + " <a href=\"http://www.csdn.net/tag/搜狐\" target=\"_blank\">搜狐</a>\n" + " </div>"); ArrayList< String> linkList = new ArrayList< String>(); while (m.find()) { String link = m.group(2).trim(); System.out.println(link); }
时间: 2024-11-07 11:27:52