1import re
2line = re.sub(r"</?\[\d+>", "", line)
3
4# Comented version
5line = re.sub(r"""
6 (?x) # Use free-spacing mode.
7 < # Match a literal '<'
8 /? # Optionally match a '/'
9 \[ # Match a literal '['
10 \d+ # Match one or more digits
11 > # Match a literal '>'
12 """, "", line)
13