Pattern Syntax

It’s beyond the scope of this book to teach regular expressions in their entirety. But it’s not necessary to learn anything close to the entirety of regular expressions to productively use them to process text. In the rest of this chapter, we’ll take a tour of the fundamentals of regular expressions—that 20 percent of functionality that allows you to perform 80 percent of the tasks you’ll encounter.

Regular expression syntax is, as we’ve discussed, famously terse. This terseness makes it relatively unintuitive. There’s sometimes no astoundingly logical reason why a particular special character represents a particular pattern, apart from that it hadn’t already been used for something else. But this terseness brings great power, ...

Get Text Processing with Ruby now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.