• + 2 comments

    I thought it should be done with a single regex, and turns out it can be done:

    import re
    [print('Valid') if re.match(r'^(?!.*(.).*\1)(?=(?:.*[A-Z]){2,})(?=(?:.*\d){3,})[a-zA-Z0-9]{10}$', input()) else print('Invalid') for _ in range(int(input()))]
    

    Explanation:

    1. (?!.*(.).*\1) checks no repeating characters;
    2. (?=(?:.*[A-Z]){2,}) checks at least 2 uppercase letters;
    3. (?=(?:.*\d){3,}) checks at least 3 digits;
    4. [a-zA-Z0-9]{10} checks exactly 10 alphanumeric characters.

    Inspiration taken from this stackoverflow question.

    PS: Since I use re.match, the ^ at the beginning is unnecessary but I put it there anyway out of good habit.