我试图在模式中获得2个字符串,但我无法得到它们。
我已经检查了几个帖子,我想也许我可以使用.group()
访问字符串,但没有运气。
private static void addUlrToList(String text){
Pattern pattern = Pattern.compile("url=(.*?)<br>name=(.*?)<br>");
Matcher matcher = pattern.matcher(text);
while(matcher.find()) {
Log.d(DEBUG_TAG1, "found");
for (int i = 1; i <= matcher.groupCount(); i++) {
Log.d(DEBUG_TAG1, "? url:" + matcher.group(i));
}
}
}
它甚至没有进入while循环,就好像它甚至没有找到与模式的匹配。
我错过了什么?
编辑: 输入字符串是:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Insert title here</title></head><body>OK<br>url=images/cartoons/<br>name=cartoons2_208x150<br>url=images/cartoons/<br>name=cartoons_208x150<br></body></html>