获取大括号小括号内容
项目开发用到了,暂做个简单记录
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+";"); } }
匹配大括号和小括号的表达式,只有转义后面的符号变了,是不是也可以换成别的
对称的符号呢
判断数字或者小数或数字小数混合
整数 ^([0-9]{1,}[.][0-9]*)$
小数 ^([0-9]{1,}[.][0-9]*)$
测试的时候我也找了不少博客,感觉多数人的都不能避免数字中的特殊符号
小数和数字混合 (^[0-9]*$)|(^([0-9]{1,}[.][0-9]*)$)
ps:java使用正则表达式提取小括号中的内容
public class Test { public static List