Exercise 2 solution import re log = """2026-11-02 ERROR disk full 2026-11-02 info started 2026-11-03 Warn cpu high 2026-11-03 debug noise""" pat = r"^(?P\d{4}-\d{2}-\d{2}) (?Perror|warn)\s+(?P.*)$" for m in re.finditer(pat, log, re.I | re.M): print(m.groupdict()) # {'date': '2026-11-02', 'level': 'ERROR', 'msg': 'disk full'} # {'date': '2026-11-03', 'level': 'Warn', 'msg': 'cpu high'} print(re.findall(pat, log)) # [] (In the script, the log lines must start at the left margin of the string, not indented, or ^ will not line up; the output above is from the unindented version, which was run.) Explanation: re.M lets ^ and $ match at each line, and re.I lets "ERROR" and "Warn" match the lower-case words in the pattern. Without the flags, ^ can only match at the start of the whole string and $ only at its end, and the level words are case-sensitive, so no match is possible and findall returns an empty list.