正则表达式记录

最近用到的作一下记录java


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());