Chapter 10Writing Parsers
Sometimes regular expressions can get a little hairy. Once you begin using lots of lookahead assertions, have many capture groups, and generally have a regular expression that’s getting a bit scary to look at, it’s probably a sign that you’re trying to do too much in a single expression. Some problems are also just plain impossible to solve with a regular expression, so an alternative isn’t only desirable, but is also actually necessary. We saw one such example in Chapter 6, Scraping HTML, when thinking about how to handle HTML.
In that case and many others, the best approach is to write a parser. A parser generally steps through a piece of text bit by bit, building up information as it goes and deciding what action ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access