Groups and sub

Parentheses in a pattern make groups, which pull pieces out of a match. m.group(1) is the first group and m.groups() gives them all as a tuple, ready to unpack.

Named groups are easier to read: (?P<level>\w+). Then m["level"] gets it, and m.groupdict() returns a dict of every named group.

re.match only matches at the start of the text. re.fullmatch must match the whole text, which is what you want for validating input like a postcode.

re.sub(pattern, replacement, text) replaces every match. In the replacement, \1 and \2 refer back to groups, so you can reorder pieces.

If you use one pattern many times, re.compile(pattern) gives you an object with the same methods. Python caches recent patterns anyway, so this is mostly about readability.

Run it, then use re.sub to turn the date 2024-03-01 into 01/03/2024.