各位代码如下:
package com.butiao.util.web;import java.util.regex.*;public class Test1 {
public static void main(String[] args) {
String str = "<html><body><a   href =http://www.sina.com:8080/index.html?id=1&u=9>首页</a><br><a   href=\"last.html\">未页</a>";
str = str + "<p>asfasfs</p>";
str = str + "<a ggg href=\"first.html\">第一页</a>dddddd" +
"<a href=\"mp3.baidu.com/m?tn=baidump3&ct=134217728&lm=-1&\">MP3</a>" +
"</body></html>";
// System.out.println (str);
//String regstr = "<a.+?href\\s*=\\s*(\"|'|)\\b(.+?)\\b(?:\\s.*)?>(.+?)</a>";
String   regstr=  "<a.+?href\\s*=\\s*(\"|'|)\\b(.+?)\\b\\1(?:\\s.*)?>(.+?)</a>";
System.out.println(str);
Pattern p = Pattern.compile(regstr);
Matcher m = p.matcher(str);
while (m.find()) {
System.out.println(">>>>"+m.group());
System.out.println(m.group(1)+":" + m.group(2) + "===" + m.group(3));
} System.out.println("该次查找获得匹配组的数量为:" + m.groupCount()); }
}为什么不能匹配第四个href呢?
把那个最后面的&去掉就可以匹配,为什么,请指教,如何才能把第四个匹配呢?