Exercise 2 solution import re pc = re.compile(r"[A-Z]{1,2}\d[A-Z\d]? \d[A-Z]{2}") for s in ["EH1 1YZ", "SW1A 1AA", "M1 1AE", "eh1 1yz", "EH11 1YZ", "EH1 1Y"]: print(s, bool(pc.fullmatch(s))) # EH1 1YZ True # SW1A 1AA True # M1 1AE True # eh1 1yz False # EH11 1YZ True # EH1 1Y False (All lines were run and printed exactly what is shown.) Explanation: one or two letters, a digit, an optional letter or digit, a space, a digit and two letters. Lower case fails because there is no re.IGNORECASE. Note that "EH11 1YZ" passes: this shape check cannot know which codes really exist, only that the text looks right.