日期:2014-05-20 浏览次数:20730 次
//几种url href="http://diy.sina.com.cn/cardshow.php" target="_blank"> href=http://video.sina.com.cn/p/sports/k/v/2011-10-17/092261530255.html target="_blank"> href="http://auto.sina.com.cn/?c=spr_web_sina_sina_www_T001">
public static String getPaperName(String url){ String res = ""; Pattern p = Pattern.compile("href=\"?(.*?)[\"|\\s)]"); Matcher m = p.matcher(url); while(m.find()){ res = m.group(1); } return res; } public static void main(String[] args) { System.out.println(getPaperName("href=\"http://diy.sina.com.cn/cardshow.php\" target=\"_blank\">")); System.out.println(getPaperName("href=http://video.sina.com.cn/p/sports/k/v/2011-10-17/092261530255.html target=\"_blank\">")); System.out.println(getPaperName("href=\"http://auto.sina.com.cn/?c=spr_web_sina_sina_www_T001\">")); }
------解决方案--------------------
http(s)?://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?