37,720
社区成员
发帖
与我相关
我的任务
分享
/**
* 解析HTML字符串提取分组数据,格式:<br>
* <div class="className">
* @throws IOException IOException
*/
public void doAnalyseHTML() throws IOException {
String srcStr = doLoadFile();
//String regStr = "(<div\\sclass=\"drag\"[^>]+>[^<>]*(((?open<div[^>]*>)[^<>]*)+((?-open</div>)[^<>]*)+)*(?(open)(?!))</div>)+";
String regStr = "<div\\sclass=\"drag\"[^>]*>(<div[^>]*>(.*)</div>|.)*?</div>";
Matcher matcher = Pattern.compile(regStr, Pattern.DOTALL).matcher(srcStr);
System.out.println("isMatcher:" + matcher.matches() + ":" + matcher.groupCount());
while (matcher.find()) {
int count = matcher.groupCount();
for (int i = 0; i < count; i++) {
System.out.println(i + ":" + matcher.group(i));
}
}
}