Command Palette

Search for a command to run...

Hectal
Phase 3: Strings and Text in Depth
Python · Exercise 6 of 6 Previous
Intermediate

Pull codes out of text with a regex

text holds "Order A-1042 shipped on 2026-10-09 to PIN 560001, then B-77 on 2026-11-02.". Use the re module and raw strings to create three variables:

codes is the list of order codes (a capital letter, a dash, then digits): ['A-1042', 'B-77']. dates is the list of dates in the form 2026-10-09. pin is the six-digit number that stands alone (not part of a longer number), as a string, found with re.search and .group(). (re.findall returns every match as a list; re.search finds the first match. Both are in Topic 3.6.)

What Check tests

  1. codes is ['A-1042', 'B-77']
  2. dates holds both dates
  3. pin is 560001
  4. The patterns are raw strings
  5. The program ends without an error

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.