1
1.2.3
1.2.3.4.5The regular expression to match: "^\\d+(\\d*.)*\\d+$"
Java code:
System.out.println(Pattern.matches("^\\d+(\\d*.)*\\d+$", "1")); // true System.out.println(Pattern.matches("^\\d+(\\d*.)*\\d+$", "1.2.3")); // true System.out.println(Pattern.matches("^\\d+(\\d*.)*\\d+$", "1.2.a")); // false System.out.println(Pattern.matches("^\\d+(\\d*.)*\\d+$", "1.2.3.")); // false
No comments:
Post a Comment