Reputation: 11
public void test(){
String source = "hello<a>goodA</a>boys can <a href=\"www.baidu.com\">goodB</a>\"\n"
+ " + \"this can help";
Pattern pattern = Pattern.compile("<a[\\s+.*?>|>](.*?)</a>");
Matcher matcher = pattern.matcher(source);
while (matcher.find()){
System.out.println("laozhu:" + matcher.group(1));
}
}
Output:
laozhu:goodA
laozhu:href="www.baidu.com">goodB
Why the second match is not laozhu:goodB
?
Upvotes: 1
Views: 59