learning-it by example

Back to the video

Regex for Data Cleaning: Extract IDs and Phones in Python

Seven made-up messy notes: two regex patterns pull out 5 order ids and 5 phone numbers, and miss 1.

Video #151 ยท Python for data

Steps in the video

  1. 0:00 Seven messy notes: five order ids, five phones, one missed
  2. 0:23 The idea
  3. 0:47 Setup
  4. 1:11 The made-up notes
  5. 1:32 Order ids
  6. 2:05 The phone pattern
  7. 2:34 Rebuild and redact
  8. 2:58 The run, ids
  9. 3:52 Three traps
  10. 4:49 What this does not show
  11. 5:16 Mistakes to avoid
  12. 5:44 My take and next steps
  13. 6:04 Recap

Files

  • clean.py (22 lines)
  • notes.py (10 lines)
  • run.py (29 lines)

Download the code (zip)

Tested with

Python 3.12.15

What this does not show

Seven made-up notes and patterns for only the formats shown, so the run says nothing about real, larger or multilingual text.

Sources

Learning IT by Example.