Challenge 1
Validate the whole code string: exactly two uppercase letters, a hyphen, then four digits.
import re
code = "ZX-7042"
if :
print("valid")
else:
print("invalid")
Press Ctrl⌘Enter to check your answer
Practice whole-string validation, named groups, lazy match iteration, and readable whitespace normalization.
Challenge 1
import re
code = "ZX-7042"
if :
print("valid")
else:
print("invalid")
Press Ctrl⌘Enter to check your answer
Challenge 2
import re
match = re.fullmatch(r"(?P<item>[A-Za-z]+):(?P<count>\d+)", "pens:12")
if match:
print()
Press Ctrl⌘Enter to check your answer
Challenge 3
import re
text = "R2 D14 Q8"
print([match.group() for match in re.finditer()])
Press Ctrl⌘Enter to check your answer
Challenge 4
import re
raw = " alpha\t beta gamma "
normalized =
print(normalized)
Press Ctrl⌘Enter to check your answer