日期:2014-05-20 浏览次数:20653 次
String text = "vlsdfjs;lfasal;fjdslfjsdalkfjsadlk{{内容1}}xxx{{内容1}}aaa{{内容1}}aa{{内容1}}aa{{内容1}}adsfasdfsda"; String regExp = "\\{\\{(.*?)\\}\\}"; Matcher m = Pattern.compile(regExp).matcher(text); while (m.find()) System.out.println(m.group(1));
------解决方案--------------------
是要最里层{}的内容吗?如果是这样的情况{{xx}yy{zz}},是取xx和zz吗?
String s = "vlsdfjs;lfasal;fjdslfjsdalkfjsadlk{{内容1}yyy{内容2}}xxx{{内容1}zzz{内容3}}aaa{{内容1}}aa{{内容1}}aa{{内容1}}adsfasdfsda"; Pattern p = Pattern.compile("[{]([^{}]*)[}]"); Matcher m = p.matcher(s); while (m.find()) { System.out.println(m.group(1)); }