Sort by

recency

|

529 Discussions

|

  • + 0 comments

    ''' (?=(?:.\d.){3,}) => This is a lookahead to check that the string contains at least 3 digits (0-9). (?=(?:.[A-Z].){2,}) => This is a lookahead to check that the string contains at least 2 Uppercase letters (A-Z). (?!.(.).\1) => ensure that no character repeats. '^', '$' [a-zA-Z0-9]{10} => This part matches exactly 10 alphanumeric characters. ''' import re
    for _ in range(int(input())): print("Valid" if re.match(r"^(?=(?:.\d.){3,})(?=(?:.[A-Z].){2,})(?!.(.).\1)[a-zA-Z0-9]{10}$", input()) else "Invalid")

  • + 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")
    
  • + 0 comments

    import re

    def is_valid_uid(uid): if len(uid) != 10 or not uid.isalnum(): return False if len(re.findall(r'[A-Z]', uid)) < 2: return False if len(re.findall(r'\d', uid)) < 3: return False if len(set(uid)) != len(uid): return False return True

    if name == 'main': n = int(input()) for _ in range(n): uid = input().strip() if is_valid_uid(uid): print("Valid") else: print("Invalid")

  • + 0 comments
    import re
    p = r'^(?=.*[A-Z].*[A-Z])(?=.*\d.*\d.*\d)[a-zA-Z0-9]{10}$'
    for _ in range(int(input())):
        s = input()
        print("Valid" if re.match(p, s) and len(s) == len(set(s)) else "Invalid")
    
  • + 0 comments

    k=int(input())
    for _ in range(k):
        i=input()
        s=set(i)
        u=[j for j in i if j.isupper()]
        d=[j for j in i if j.isdigit()]
        if len(i)==10 and len(s)==10 and i.isalnum() and len(u)>1 and len(d)>2:
            print("Valid")
        else:
            print("Invalid")