16 · Text I — regex
Tuesday, Oct 20, 2026
Materials for this session are not published yet. They appear here before class.
Objectives
By the end of this session you can:
- Read and write practical regular expressions.
- Extract structured fields from messy text.
- Pair every pattern with positive and negative tests.
- Judge when a regex beats a model, and when it doesn’t.
What we cover
- What text has measured: media slant, FOMC language, skills in job ads — the text-as-data classics.
stringr; regex from literals to character classes, quantifiers, anchors, and groups.- Counting words: tokenize,
table(), stop words, term frequencies — the dictionary tier that answered those classic papers, and still the right first move on any corpus. Readability metrics in one slide; fixing a broken character encoding in one line. - Regex and counting as the cheap, deterministic tools you try before reaching for a model — session 17 is for what they can’t do.
Verification habit. Every pattern ships with a should-match test and a should-NOT-match test.