String content="<br>{Es_kk}<br>{Es_bb}<br>";
Pattern quotePattern=Pattern.compile("\\{Es_\\S*}");
Matcher quoteMatch=quotePattern.matcher(content);
上面的程序是用正则表达式取出"{Es_kk}<br>{Es_bb}";
但是
我现在打算分别取出"{Es_kk}"和"{Es_bb}"的内容,看一下上面的正则表达式怎么修改

解决方案 »

  1.   

    这样试试:
           String content="<br>{Es_kk}<br>{Es_bb}<br>";
           Pattern quotePattern=Pattern.compile("(\\{Es_[^}]*})<br>(\\{Es_[^}]*})<br>");
           Matcher quoteMatch=quotePattern.matcher(content);
           quoteMatch.find(); 
           for(int i=1;i<=quoteMatch.groupCount();i++)
              System.out.println(quoteMatch.group(i));
      

  2.   

    String content="<br>{Es_kk}<br>{Es_bb}<br>";
       Pattern quotePattern=Pattern.compile("(\\{Es_[^}]*})<br>(\\{Es_[^}]*})<br>");
       Matcher quoteMatch=quotePattern.matcher(content);
       if(quoteMatch.find()) 
       {  
           for(int i=1;i<=quoteMatch.groupCount();i++)
              System.out.println(quoteMatch.group(i));
       }
      

  3.   

    \\{Es_\\S*?\\}
    区别在于在 "*" 后有一个 "?",称为 "非贪婪模式",搂主可参阅文章:
    http://www.regexlab.com/zh/regref.htm