Field work
Real text — receipts, logs, emails — where one pattern combines everything you learned: classes, quantifiers, anchors and groups.
Drill it: Real-world formats →
Builds on Golf techniques
What you'll learn
Steps · 12
- 01Into the fieldBriefing
- 02Read the receiptHunt
- 03Scrape the emailsHunt
- 04Validate usernamesHunt
- 05Sift the logHunt
- 06Find the hashtagsHunt
- 07Match 24-hour timesHunt
- 08Read the changelogHunt
- 09Validate hex coloursHunt
- 10Your turnHunt
- 11Field golfHunt
- 12Field work completeBriefing
Regex on real text: logs, receipts and emails
Real text is messy. A receipt mixes item names, prices and dates; a server log packs a timestamp, a level and a message into one line; an email has headers, quotes and a signature. Using regex on real text means finding the pieces you need inside all that noise, not checking one clean value.
This is where the basics meet. A class picks the characters, a quantifier sets how many, an anchor or \b pins where a match may start or end, and a group with | lists the variations people actually write. In this track you highlight prices, emails and dates in real snippets, and validate a few formats along the way.
Practise on text that looks like your own data. Copy a few real lines, include the awkward ones, and check what your pattern lights up as well as what it misses. A pattern that works on three tidy lines often fails on the fourth.
Examples
Catches
- ERROR disk full
- WARN slow query
Spares
- INFO user saw ERROR
- WARNING: low disk
The
^keeps the level at the start of the line, and\bstopsWARNINGfrom passing asWARN.Catches
- Order ORD-20481
- ref ORD-1234 paid
Spares
- ORD-12
- WORD-5000
\bkeepsWORD-5000out, and{4,}asks for at least four digits.Catches
- save 15%
- VAT 7.5%
- tax 7,5%
Spares
- 15 percent
- page 2
The optional group reads
15%,7.5%and the European7,5%with one pattern.Catches
- Re: invoice
- FWD: menu
- fw: slides
Spares
- Review: draft
- Invoice re: May
The
iflag coversRe,REandre, and^ignores are:in the middle of a subject line.
Common mistakes
- Matching inside longer things.
\d{4}finds a year, but it also finds four digits inside a phone number or an order ID; add\bor the surrounding text to pin it. - Letting `. *
run away. It is greedy, so\(.*\)on a line with two pairs of brackets grabs everything from the first(to the last); a class such as[^)]*` stops at the first one. - Testing only the tidy lines. Real data has extra spaces, mixed case and missing fields, so test with the ugly lines too and decide which ones you want to spare.
Drill it: Real-world formats →
Read more: Real-world validators →
Read more: Email regex: copy-ready patterns that actually work →
Read more: Regex for phone numbers: US formats, E.164, and when to stop →