最近用到的作一下記錄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());