Question 8
Back to Exercise
What is the output of the following Python program?
import re
print(re.sub(r"(\d{4})-(\d{2})-(\d{2})", r"\3/\2/\1", "From 2026-11-30 to 2026-12-05"))
- A From 2026/11/30 to 2026/12/05
- B From \3/\2/\1 to \3/\2/\1
- C From 30/11/2026 to 2026-12-05
- D From 30/11/2026 to 05/12/2026 Correct
Correct Answer: Option D
sub replaces every match; \3, \2 and \1 insert the captured day, month and year.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!