微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

正则表达式记录

最近用到的做一下记录


String name = "10310";
//以非0数字开头的数字串
Pattern p = Pattern.compile("^[1-9]+\\d*");
Matcher m = p.matcher(name);
System.out.println(m.matches());
//以数字.数字.数字.数字格式的串
Pattern pt = Pattern.compile("\\d*[.]\\d*[.]\\d*[.]\\d*");
Matcher ma = pt.matcher("p=10.10.10");
System.out.println(ma.matches());
//以{内容},{内容}...{内容}格式的串
String test = "{fdfdfdfdfdfdfd}";
Pattern ptw = Pattern.compile("(\\{[^{},]*\\}[\\,]*[\n\r]*){1,}");
Matcher maw = ptw.matcher("{gfdgfd}");
System.out.println(maw.matches());
//以数字,数字,....,数字格式的串
Pattern ptwe = Pattern.compile("[(\\d+)\\,(\\d+)]*");
Matcher mawe = ptwe.matcher("333");
System.out.println(mawe.matches());

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐