Regular Expressions: The Guide I Always Wanted (2026)
Regex isn't magic. It's a mini-language for pattern matching, and once you learn the basics, you'll use it everywhere.
The Mental Model
A regex is a pattern that matches (or doesn't match) text.
Think of it as: "Find all strings that look like THIS"
Components: → Literals: exact characters to match (a, b, 1, @) → Character classes: WHAT can match ([a-z], \d, \w) → Quantifiers: HOW MANY times (+, *, ?, {3}) → Anchors: WHERE in the string (^, $, \b) → Groups: capture parts of the match ((...)) → Alternation: OR logic (|)
The secret to reading regex: left to right, character by character.
Enter fullscreen mode
Exit fullscreen mode
Character Classes
// Exact match / hello / // Matches "hello" in "say hello there" /Hello/ // Case sensitive! Won't match "hello"
// Dot (matches any single character EXCEPT newline) / h . t / // "hat", "hot", "hit", "h3t"...…