java正则表达式获取⼤括号⼩括号内容并判断数字和⼩数
亲测可⽤
获取⼤括号⼩括号内容
项⽬开发⽤到了,暂做个简单记录
private static String regex = "\\{([^}]*)\\}";//匹配⼤括号
private static String regexx = "\\(([^}]*)\\)";//匹配⼩括号
public static void main(String[] args) {
String dakuohao = "{a+b}={c+d}>{d}";
Pattern compile = Patternpile(regex);
Matcher matcher = compile.matcher(dakuohao);
while(matcher.find()){
String group = up();
System.out.print(group+";");
}
System.out.println();
String xiaokuohao = "(a+b)=(c+d)>(d)";
Pattern comp = Patternpile(regex);
Matcher mat = comp.matcher(dakuohao);
while(mat.find()){
String group = up();
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<String> getMsg(String msg) {
List<String> list = new ArrayList<String>();
Pattern p = Patternpile("(\\()([0-9a-zA-Z\\.\\/\\=])*(\\))");
Matcher m = p.matcher(msg);
while (m.find()) {
list.up(0).substring(1, m.group().length() - 1));
}
return list;
}
public static void main(String[] args) throws Exception {
String msg = "mSurface=Surface(name=com.bbk.launcher2/com.bbk.launcher2.Launcher)";
List<String> list = getMsg(msg);
System.out.println(list);
}
}
总结
以上所述是⼩编给⼤家介绍的java正则表达式获取⼤括号⼩括号内容并判断数字和⼩数亲测可⽤,希望对⼤家有所帮助,如果⼤家有任何疑问请给我留⾔,⼩编会及时回复⼤家的。在此也⾮常感谢⼤家对⽹站的⽀持!
如果你觉得本⽂对你有帮助,欢迎转载,烦请注明出处,谢谢!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论