网页中链接的正则表达式
String re = "<a\\s.*?href\\s*=\\s*\'?\"?([^(\\s\")]+)\\s*\'?\"?[^>]*>(.*?)</a>";
Pattern p = Pattern.compile(re, Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE);
其中href中的内容可以用单引号也可以用双引号,还可以不加引号。
一下都可以匹配
<a href = http://energy.people.com.cn/GB/18240404.html target=\"_blank\">电监会新36条出台</a> -----href后跟有空格
<a href= http://energy.people.com.cn/GB/18240404.html target=\"_blank\">电监会新36条出台</a> -----href后没有空格
<a href=‘http://energy.people.com.cn/GB/18240404.html’ target=\"_blank\">电监会新36条出台</a> -----href后为单引号
<a href="http://energy.people.com.cn/GB/18240404.html" target=\"_blank\">电监会新36条出台</a> -----href后为双引号