Why Regular Expressions Are Jokingly Called "Write-Only" Code
Published 2026-09-14
A joke with real truth behind it
Among programmers, there's a long-standing joke that regular expressions are "write-only" — you can write one while the logic is fresh in your head, but coming back to the same pattern weeks later, even one you wrote yourself, can feel like decoding a stranger's cipher. The joke persists because it's genuinely relatable: a dense pattern like ^(?:[a-z0-9]+(?:[.-][a-z0-9]+)*)@... packs a lot of logic into a very small, symbol-heavy space with almost no descriptive naming to hint at intent.
Where regular expressions actually come from
Regular expressions trace back to formal language theory developed by mathematician Stephen Kleene in the 1950s, describing patterns a simple computing model (a finite automaton) could recognize. Ken Thompson brought the concept into practical software tooling in the 1960s, building it into early Unix text-editing tools — a lineage that's why regex syntax still feels distinctly "Unix-era" today, dense and symbol-driven rather than English-like.
Why the density is actually the point
Regex syntax is compact by design — it needs to express "one or more digits, followed by an optional space, followed by either 'kg' or 'lbs'" in a form a parsing engine can process instantly. That same compactness that makes regex powerful for the computer is exactly what makes it hard for a human to re-read later, since very little of a regex pattern maps to plain-language words.
How to write regex you can still read later
- Break complex patterns into named pieces using comments or separate named capture groups, if your regex flavor supports them.
- Test against real, varied sample text rather than just the one example that inspired the pattern, since regex logic often has edge cases invisible until you try enough inputs.
- Keep a plain-language note next to any non-trivial pattern in your codebase, since the pattern itself won't explain its own intent to the next reader.
Test yours interactively
Our Regex Tester highlights every match live against your own sample text and lists capture groups in a table, which makes verifying a pattern's actual behavior far faster than mentally tracing through the symbols.