We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Python
- Regex and Parsing
- Validating UID
- Discussions
Validating UID
Validating UID
Sort by
recency
|
532 Discussions
|
Please Login in order to post a comment
test_cases = int(input()) for i in range(test_cases): string = input() upper_count=0 digits_count=0 for ele in string: if ele.isupper(): upper_count += 1 elif ele.isdigit(): digits_count += 1
unique_count = len(string)==len(set(string)) if len(string)==10 and unique_count and string.isalnum() and upper_count >=2 and digits_count >= 3: print('Valid') else: print('Invalid')
''' (?=(?:.\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")
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?