When to use regex (and when not to)
Regex shines at:
- Extracting structured tokens from messy text (URLs, emails, IPs).
- Validating format-only correctness (zip codes, phone numbers).
- Find-and-replace transformations across whole codebases.
Reach for a real parser when:
- The format has nesting or recursion (HTML, JSON, source code).
- You need semantic validation (is this DNS-resolvable? does this user exist?).
- The grammar is published — use the parser library, not a regex.