Exercise 2 solution import re def is_code(s): return re.fullmatch(r"[A-Z]{3}-\d{4}", s) is not None for s in ["ABC-1234", "AB-1234", "ABC-12345", "abc-1234", "xABC-1234"]: print(s, is_code(s)) Output (run): ABC-1234 True AB-1234 False ABC-12345 False abc-1234 False xABC-1234 False print(bool(re.match(r"[A-Z]{3}-\d{4}", "ABC-12345"))) # True re.match only anchors the START of the string. "ABC-1234" matches the first eight characters, and the extra "5" is simply ignored, so a code that is too long is wrongly accepted. fullmatch requires the pattern to cover the whole string, so the extra digit makes it fail. (The same effect can be had with re.search and ^...$ anchors, but fullmatch says it directly.)