Rewrite Dates with Backreferences

Medium ⏱ 12 min 47% acceptance ★★★★★ 4.8
Write us_to_iso(text) converting every MM/DD/YYYY date in a document to YYYY-MM-DD using one re.sub with numbered group backreferences — the capture groups reorder themselves in the replacement string.

Examples

Example 1
Input
us_to_iso('due 07/28/2026 and 12/01/2026')
Output
'due 2026-07-28 and 2026-12-01'
Explanation

Groups are re-emitted in ISO order.

Constraints

  • One re.sub call.
  • Match \d{2}/\d{2}/\d{4} exactly.

Topics

Regular Expressionsbackreferences

Companies

SAPOracleInfosys

Hints

Hint 1

Pattern: (\d{2})/(\d{2})/(\d{4}).

Hint 2

Replacement: r'\3-\1-\2'.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.