Exercise 1 solution import re text = "Smith, Ann: 2026-11-02\nJones, Bo: 2025-01-09" out = re.sub(r"^(?P\w+), (?P\w+): (?P\d{4})-(?P\d\d)-(?P\d\d)$", r"\g \g: \g/\g/\g", text, flags=re.M) print(out) # Ann Smith: 02/11/2026 # Bo Jones: 09/01/2025 print(re.subn(r"^(\w+), (\w+)", r"\2 \1", text, flags=re.M)[1]) # 2 (All lines were run and printed exactly what is shown.) Explanation: re.M lets ^ and $ work on every line, so one call rewrites both lines. The replacement refers to the named groups with \g, which also lets the groups be reordered. subn returns a (new_string, count) tuple, so [1] is the number of substitutions made.