1 String pattern = "\\{[^\\}]+\\}"; 2 // 创建 Pattern 对象 3 Pattern r = Pattern.compile(pattern); 4 5 String str = "您好,{a||b||c},这里是{d||e||f}"; 6 // 现在创建 matcher 对象 7 Matcher m = r.matcher(str); 8 while (m.find()) { 9 System.out.println(m.group()); 10 }
打印为:
{a||b||c}
{d||e||f}