Exercise 2 solution import re pat = r"^(?=.*[a-z])(?=.*\d)(?!.*\s).{6,10}$" for s in ["abc123", "ABC123", "abcdef", "abc 123", "a1"]: print(repr(s), bool(re.fullmatch(pat, s))) # 'abc123' True # 'ABC123' False # 'abcdef' False # 'abc 123' False # 'a1' False (All lines were run and printed exactly what is shown.) Explanation: each lookahead is tested from the start of the string and consumes nothing. (?=.*[a-z]) needs a lowercase letter somewhere, (?=.*\d) needs a digit, and (?!.*\s) forbids any whitespace. The final .{6,10} then matches the whole string and enforces the length. "ABC123" fails the lowercase check, "abcdef" the digit check, "abc 123" the no-space check and "a1" the length.