Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Once a programmer had a problem. He thought he could solve it with a regular expression. Now he had two problems.
—from a fortune cookie
Suppose you had to prepare a table of contents for this book. You would need to collect all headings like “3.5 Working with regular expressions”—paragraphs that start with a number or with a number, a dot, and another number. The rest of the paragraph would be the heading. This would be cumbersome to code naïvely: iterate over each character; check whether it is a line start; if so, check whether it is a digit; if so, check whether a dot and a digit follow. Puh—lots of rope, and we haven’t even covered numbers that have more than one digit.