I want to validate a UID based on the following conditions:
- at least two uppercase letters
- at least three digits
- must only contain alphanumeric characters (a-z,A-Z,0-9)
- no character should repeat
- must be exactly 10 characters
This is the correct regex:
re.match(r'^(?=(?:.*[A-Z]){2,})(?=(?:.*\d){3,})(?!.*(.).*\1)[a-zA-Z0-9]{10}$', input())
The following two are my solutions:
#A re.match(r'^(?=(.*[A-Z]){2,})(?=(.*\d){3,})(?!.*(.).*\1)[a-zA-Z0-9]{10}$',input())
#B re.match(r'^(?=.*[A-Z]{2,})(?=.*\d{3,})(?!.*(.).*\1)[a-zA-Z0-9]{10}$',input())
A cannot match anything B can only match a few cases like:'AhBUw9r675','41726EHJIr','X6543g08QS', cantnot match cases like: 'yD09Ee83fJ','96R5ZDJg72','r57tH100Ej','h7AFN4y5dt'....etc
My question is why both of my solutions are wrong, and more specifically
for A: what are the differences between capturing and non-capturing group besides that one can return the match and be referenced while the other only search for match but return nothing
for B: when using lookahead or lookbehind assertion, when do I need to put the pattern in or not in () e.g. (?= pattern) (?= (pattern))