problem description
wrote a regular match to the mobile number Filter beautiful number AAAA
number. It can be matched, but it also encounters BUG.
- regular: ^ (? = d * (d) (d) (d) 1$) 1 [35789]\ d {9} $
-
verify the number
- 17091217777--> true
- 17097777297--> true
- 17091217297--> true
- 17091217298--> false
I really don"t understand why the number 17091217297 is true
.Code
@Test
public void AAAA(){
String phoneNo = "17091217297";
String pattern = "^(?=\\d*(\\d)(\\d)(\\d)\\1$)1[35789]\\d{9}$";
matchRule(phoneNo, pattern);
}
private void matchRule(String phoneNo, String pattern) {
Pattern pa = Pattern.compile(pattern);
Matcher ma = pa.matcher(phoneNo);
Assert.assertTrue(ma.matches());
}
expectation
expect 17091217297
regular Filter to drop, please give me some advice!