String html = "<huge_template>页面导航模板</huge_template><br>&nbsp;大家好啊<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);
     }
得到的是页面导航模板
我想要得到的是两条记录  :页面导航模板 页尾模板
怎么做啊,高手多指教啊

解决方案 »

  1.   

    <huge_template>[^<]*</huge_template>
      

  2.   

    我用的是jdk1.4.2_b28的版本,结果无法处理中文
    重新下载了一个最新的jdk1.4.2_10,结果没问题直接使用JDK的正则表达式就可以了
    String html = "(?u)<huge_template>ew</huge_template><br>&nbsp;大家好啊<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));
    }
      

  3.   

    请教下:这是与java的什么相关的?熟悉的话请详细点,3Q
      

  4.   

    谢谢: treeroot(旗鲁特) ,
    不过我用的是org.apache.oro.text.regex.*包
    这个API下应该用什么来循环读取group呢
      

  5.   

    <huge_template>(([^<]|<(?!/huge_template>))*)</huge_template>(([^<]|<(?!huge_templage>))*)<huge_template>(([^<]|<(?!/huge_template>))*)</huge_template>测试方法:(试用,开发 & 优化过程中)http://www.regexlab.com/zh/workshop.asp?pat=%3Chuge_template%3E%28%28%5B%5E%3C%5D%7C%3C%28%3F%21/huge_template%3E%29%29*%29%3C/huge_template%3E%28%28%5B%5E%3C%5D%7C%3C%28%3F%21huge_templage%3E%29%29*%29%3Chuge_template%3E%28%28%5B%5E%3C%5D%7C%3C%28%3F%21/huge_template%3E%29%29*%29%3C/huge_template%3E&txt=%22%3Chuge_template%3E%u9875%u9762%u5BFC%u822A%u6A21%u677F%3C/huge_template%3E%3Cbr%3E%26nbsp%3B%u5927%u5BB6%u597D%u554A%3Chuge_template%3E%u9875%u5C3E%u6A21%u677F%3C/huge_template%3E%22%3B