import java.util.regex.Matcher;
import java.util.regex.Pattern;public class SequenceTest {
public static void main(String[] args) {
String str = "<li><a href=\"http://news.sina.com.cn/c/2010-01-11/103319442904.shtml\" target=\"_blank\">" +
"谷超豪从教60年培养9个院士弟子 </a></li>" +
"<li><a href=http://news.sina.com.cn/c/2010-01-11/103319442904.shtml target=\"_blank\">" +
"谷超豪从教60年培养9个院士弟子 </a></li>" +
"<li><A HRef =\'http://news.sina.com.cn/c/2010-01-11/103319442904.shtml\' target=\"_blank\">" +
"谷超豪从教60年培养9个院士弟子 </a></li>";
String regex = "(?i)<a\\s+href\\s*=\\s*[\'\"]?([^\"\' ]+)[\'\"]?";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(str);
while(matcher.find()) {
System.out.println(matcher.group(1));
}
}
}
import java.util.regex.Pattern;public class SequenceTest {
public static void main(String[] args) {
String str = "<li><a href=\"http://news.sina.com.cn/c/2010-01-11/103319442904.shtml\" target=\"_blank\">" +
"谷超豪从教60年培养9个院士弟子 </a></li>" +
"<li><a href=http://news.sina.com.cn/c/2010-01-11/103319442904.shtml target=\"_blank\">" +
"谷超豪从教60年培养9个院士弟子 </a></li>" +
"<li><A HRef =\'http://news.sina.com.cn/c/2010-01-11/103319442904.shtml\' target=\"_blank\">" +
"谷超豪从教60年培养9个院士弟子 </a></li>";
String regex = "(?i)<a\\s+href\\s*=\\s*[\'\"]?([^\"\' ]+)[\'\"]?";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(str);
while(matcher.find()) {
System.out.println(matcher.group(1));
}
}
}
<li> <a href="http://news.sina.com.cn/c/2010-01-11/103319442904.shtml" target="_blank">谷超豪从教60年培养9个院士弟子 </a> </li>
STR;
preg_match_all("/<a[^<>]*href=['\"]([^'\"]+)['\"][^<>]*>/im", $str, $matches);
var_dump($matches[1]);
String html="li> <a href=\"http://news.sina.com.cn/c/2010-01-11/103319442904.shtml\" target=\"_blank\">"
+"谷超豪从教60年培养9个院士弟子 </a> </li> ";
String regex="<a\\s+.*?href=\"?(.*?)\"?\\s+.*?>(.*?)</a>";
Pattern p=Pattern.compile(regex,Pattern.CASE_INSENSITIVE);
Matcher m=p.matcher(html);
while(m.find()){
System.out.println(
"URL:"+m.group(1)
+"\n"
+"Text:"+m.group(2)
);
}
}