匹配开头和结尾
用 ^
表示开头,$
表示结尾。
匹配 D 开头,9 结尾,中间是任意个数字的字符,
String regexbeginend = "^D\\d*9$";
System.out.println("D".matches(regexbeginend));// false
System.out.println("D1".matches(regexbeginend));// false
System.out.println("D22".matches(regexbeginend));// false
System.out.println("D119".matches(regexbeginend));// true
System.out.println("D11A9".matches(regexbeginend));// false
System.out.println("D55555".matches(regexbeginend));// false
System.out.println("D666666".matches(regexbeginend));// false