- Java code
//几种urlhref="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">
我想得到href后面的有效url,正则怎么弄?
------解决方案--------------------
- Java code
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-./?%&=]*)?