Help me to see a regular Bug, solution.

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!

Mar.28,2021

your problem is not only to match 17091217297 errors, but also to make mistakes such as 17097077297 . In fact, it should be written like this
String pattern = "^ (? =\\ d * (\\ d)\\ 1\ 1\ 1\ 1\\ d {9} $") 1 [35789]\ d {9} $";

in fact, there is a stupid way to identify all the duplicates, for example:
String pattern = "^ (? =\\ d * (0000 | 1111 | 2222 | 3333 | 4444 | 5555 | 6666 | 7777 | 8888 | 9999)\\ d *) 1 [35789]\ d {9} $";


^1[35789]\\\\d{5}(\\\\d)\\\\1{3}$
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eb24b2-69b35.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eb24b2-69b35.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?