获取大括号小括号内容
项目开发用到了,暂做个简单记录
private static String regex = "\\{([^}]*)\\}";//匹配大括号
private static String regexx = "\\(([^}]*)\\)";//匹配小括号
public static void main(String[] args) {
String dakuohao = "{a+b}={c+d}>{d}";
Pattern compile = Pattern.compile(regex);
Matcher matcher = compile.matcher(dakuohao);
while(matcher.find()){
String group = matcher.group();
System.out.print(group+";");
}
System.out.println();
String xiaokuohao = "(a+b)=(c+d)>(d)";
Pattern comp = Pattern.compile(regex);
Matcher mat = comp.matcher(dakuohao);
while(mat.find()){
String group = mat.group();
System.out.print(group+";");
}
}
匹配大括号和小括号的表达式&