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
codesis['A-1042', 'B-77']datesholds both datespinis560001- The patterns are raw strings
- 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.