The true power of regular expressions (2012)

npopov.com
August 3, 2026
21 min read
48/100
Summary
Regular expressions can be effective for parsing specific aspects of HTML, despite the common belief that HTML is not regular. Using regular expressions in certain contexts can yield practical results, challenging the notion that XML parsers are the only viable solution.
Key Takeaways
- Regular expressions can match more than just regular grammars; modern implementations can handle complex patterns beyond the formal definition of regularity.
- The grammar defining natural numbers can be expressed as a regular expression [0-9]+, demonstrating the conciseness of regex compared to traditional grammar definitions.
- The article emphasizes that while formal regular expressions are limited to regular languages, practical regex implementations in programming languages can parse a wider range of patterns.
- The Chomsky hierarchy is referenced to categorize different types of languages, highlighting the complexity of language parsing in computational theory.
Coverage & discussions
Hacker News · npopov.com
Community discussions
Historical count: 5 · 5 saved in sample · Historical sample
Analysis ready
Community Sentiment
Positives
- Regex is compact and declarative, offering a unique solution to text processing that alternatives like substring searches simply can't match.
- Despite its complexity, regex has a rich composability potential that many programming languages overlook, limiting its full utility.
- For many practical applications, such as counting tags, regex proves effective even if it isn't suited for parsing entire documents.
Concerns
- Reading regex can feel like deciphering a complex mathematical formula, making it daunting for many developers who struggle with its dense syntax.
- The conflation of regex with specific implementations like PCRE misleads users about its true capabilities, especially regarding performance and complexity.
- Regular expressions can be notoriously slow depending on how they are crafted, which can lead to significant performance issues in real-world applications.
Related Articles

I no longer care to work on any Ruby gems so I've archived all my repositories
Oct 19, 2026

The future of programming (1982)
Oct 17, 2026

“Code was never the hard part” is an insult to all programmers
Aug 8, 2026

Taste Is All That's Left
Aug 6, 2026

Why is programming so captivating, yet so agonizing?
Jul 24, 2026