项目开发用到了,暂做个简单记录
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
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]*)$)
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
public class Test {
public static List<String> getMsg(String msg) {
List<String> list = new ArrayList<String>();
Pattern p = Pattern.compile("(\\\\()([0-9a-zA-Z\\\\.\\\\/\\\\=])*(\\\\))");
Matcher m = p.matcher(msg);
while (m.find()) {
list.add(m.group(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正则表达式获取大括号小括号内容并判断数字和小数亲测可用,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对快网idc网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
相关文章
猜你喜欢
- 64M VPS建站:怎样选择合适的域名和SSL证书? 2025-06-10
- 64M VPS建站:怎样优化以提高网站加载速度? 2025-06-10
- 64M VPS建站:是否适合初学者操作和管理? 2025-06-10
- ASP.NET自助建站系统中的用户注册和登录功能定制方法 2025-06-10
- ASP.NET自助建站系统的域名绑定与解析教程 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-06-04 92
-
2025-05-27 105
-
2025-05-29 98
-
2025-05-25 97
-
微软承认 Windows 11 下 Outlook 搜索邮件卡死问题(附临时解决方法)
2025-05-27 30
热门评论





