REAL-WORLD CHALLENGES

Email addresses

Pull email addresses out of free text with sets, quantifiers and escaping.

Extract email addresses from a line. Think in three pieces: a local part before the @, the @ itself, then a domain that ends in a dot and a top-level suffix. A workable shape is [\w.+-]+@[\w.-]+\.\w{2,} - word characters plus a few punctuation marks, an @, a domain, an escaped dot, then at least two more characters.

A regex checks shape, not validity: this pattern accepts "a@b.io" and would also accept addresses no mail server could deliver. Fully RFC-correct email matching is famously gnarly - for everyday extraction this practical shape is what you actually want.

PRACTICE - 2 DRILLS 0/2 DONE
DRILL 1/2- Extract emails

Match every email address in the line.

/ /
contact jane.doe@example.com please
must match: "jane.doe@example.com"
two: a@b.io and c.d+tag@sub.domain.org
must match: "a@b.io" "c.d+tag@sub.domain.org"
no email here, just text
must match nothing
sign alone @ and word
must match nothing
DRILL 2/2- Just the domain

Match only the domain of each email - the part after the @, with the @ excluded.

/ /
jane@example.com and bob@mail.co.uk
must match: "example.com" "mail.co.uk"
reach support@acme.io now
must match: "acme.io"
no domains here
must match nothing