String html = "<huge_template>页面导航模板</huge_template><br> 大家好啊<huge_template>页尾模板</huge_template>";
String regexpForFontTag = "<\\s*huge_template\\s*>([^<]*)\\s*<\\s*/huge_template\\s*>";
String regexpForFontAttrib = "([a-z]+)\\s*=\\s*\"([^\"]+)\"";
PatternCompiler compiler = new Perl5Compiler();
Pattern patternForFontTag = compiler.compile(regexpForFontTag,
Perl5Compiler.CASE_INSENSITIVE_MASK);
Pattern patternForFontAttrib = compiler.compile(regexpForFontAttrib,
Perl5Compiler.CASE_INSENSITIVE_MASK);
PatternMatcher matcher=new Perl5Matcher();
while (matcher.contains(html,patternForFontTag)){
MatchResult result=matcher.getMatch();
String attrib=result.group(1);
System.out.print(attrib);
}
得到的是页面导航模板
我想要得到的是两条记录 :页面导航模板 页尾模板
怎么做啊,高手多指教啊
String regexpForFontTag = "<\\s*huge_template\\s*>([^<]*)\\s*<\\s*/huge_template\\s*>";
String regexpForFontAttrib = "([a-z]+)\\s*=\\s*\"([^\"]+)\"";
PatternCompiler compiler = new Perl5Compiler();
Pattern patternForFontTag = compiler.compile(regexpForFontTag,
Perl5Compiler.CASE_INSENSITIVE_MASK);
Pattern patternForFontAttrib = compiler.compile(regexpForFontAttrib,
Perl5Compiler.CASE_INSENSITIVE_MASK);
PatternMatcher matcher=new Perl5Matcher();
while (matcher.contains(html,patternForFontTag)){
MatchResult result=matcher.getMatch();
String attrib=result.group(1);
System.out.print(attrib);
}
得到的是页面导航模板
我想要得到的是两条记录 :页面导航模板 页尾模板
怎么做啊,高手多指教啊
重新下载了一个最新的jdk1.4.2_10,结果没问题直接使用JDK的正则表达式就可以了
String html = "(?u)<huge_template>ew</huge_template><br> 大家好啊<huge_template>页尾模板</huge_template>";
String regexpForFontTag = "<huge_template>([^<]*)</huge_template>";
Pattern p=Pattern.compile(regexpForFontTag);
Matcher m=p.matcher(html);
while(m.find()){
System.out.println(m.group(1));
}
不过我用的是org.apache.oro.text.regex.*包
这个API下应该用什么来循环读取group呢