Regular Expressions: Stop Copy-Pasting Patterns You Can't Read
This course is for a developer who has pasted plenty of regexes off Stack Overflow but freezes when asked to write or even read one. You can tell it "matches an email, probably," but \d, [^a-z], +, ^, (…), and .+? are still line noise. The fix is not collecting more patterns to paste. It is learning the small alphabet a regex is built from, one piece at a time — literals, character classes, quantifiers, anchors, groups, alternation, and greedy-vs-lazy — until you can look at an unfamiliar pattern and say out loud what it does. We use JavaScript's regex syntax as the concrete vehicle, but the pieces transfer to almost every language.
By the end you'll be able to (course objectives):
- Say what a regex is, match plain literal text, and tell a literal character from a special one (a metacharacter).
- Match a set of characters with character classes (
[abc], ranges, negation, and the\d/\w/\sshorthands), and know exactly what.does and does not match. - Control how many times something repeats with
*,+,?, and{n,m}. - Pin a match to the start, end, or a word boundary with the anchors
^,$, and\b. - Pull pieces out of a match with capturing groups, and offer choices with alternation (
|). - Explain the difference between greedy (
.+) and lazy (.+?) matching, then write and verify a real validator in a live console.
Prerequisites: You can read basic code — strings, variables, and calling a function like "text".match(...). No prior regex vocabulary is assumed: character classes, quantifiers, anchors, groups, and greedy/lazy are all taught from zero.
Practice environment: You use your own browser DevTools console or a Node.js REPL — this course has no embedded sandbox for the exercises. Every pattern here has been run in a real JavaScript engine, and every exercise points you at a console you open yourself.
Lessons
Sources listed in sources.md.