• + 0 comments

    i tried to write the code in a clearer way, using re.VERBOSE, however i am unable to complete the excercise with this. in fact, test 3 fails expecting, for example, string "944A4NKtE2" to be valid (even though the character '4' is repeating). How so? is someone able to help me understand this?

    import re
    
    pattern = re.compile(r"""
        ^
        (?=.*[A-Z]{2,})     # At least 2 uppercase English alphabet characters
        (?=.*\d{3,})        # At least 3 digits
        (?=.*[a-zA-Z\d])    # Only alphanumeric characters
        (?!.*(.).*\1+.*)       # No repeated character
        .{10}
        $
        """, re.VERBOSE)
    
    for _ in range(int(input())):
        correspondence = pattern.search(input())
        if correspondence:
            print("Valid")
        else:
            print("Invalid")