额 你肯能理解错了 我的意思是把<ca><pre>(.+?)</pre></ca>  懂了吧。。

解决方案 »

  1.   


    String s = "<cd><pre>不需要</pre></cd><ca><pre>需要1</pre></ca><cn><pre>需要2</pre></cn>"+
    "<cn><pre>需要3</pre></cn>";
    String reg = "<pre>(.*?)</pre>";
    Matcher match = Pattern.compile(reg).matcher(s);
    while(match.find()){
    System.out.println(match.group(1));
    }
      

  2.   


    String s = "<cd><pre>不需要</pre></cd><ca><pre>需要1</pre></ca><cn><pre>需要2</pre></cn>"+"<cn><pre>需要3</pre></cn>";
    String reg = "(?<=<ca><pre>).*?(?=</pre></ca>)|(?<=<cn><pre>).*?(?=</pre></cn>)";
    Matcher match = Pattern.compile(reg).matcher(s);
    while(match.find()){
    System.out.println(match.group());
    }
      

  3.   

    我也学Java了为什么楼主问的问题我一点都不懂呢,真是惭愧啊,大学白上了