Mastering Regular Expressions, Second Edition
by Jeffrey E. F. Friedl
1 recommendation

Get it

Recommendations on Mastering Regular Expressions, Second Edition

Recommendations from domain experts (curated by Highlyreco)

Steve Yegge's Review:

Our first O'Reilly title in the list! It has an owl on the front; owls are known for their, uh, regular, erm, never mind. It's not always clear how O'Reilly picks their colophons.

This is a great book for exactly, precisely the reason that all O'Reilly books are great: it covers complex material in a way that's accessible to uncomplex people. Ever notice that "O'Reilly" sounds just like "for Dummies" underwater? And quite frankly, I'm the proud owner of several "for Dummies" books (publisher: IDG, which I believe stands for "IDiot's Guide"); they're very similar to O'Reilly books in their general approach and target audience. It might sound like I'm bashing on for-Dummies books, but quite the contrary -- I hate badly-written, pretentious books that don't talk to me like a person. I've often wished that O'Reilly would publish a Computer Science series.

Anyway, regular expressions are a mini-language for generating and matching regular languages, a concept introduced by the famous linguist Noam Chomsky. A "mini-language" is a special-purpose language with its own jargon and structure. A famous example is StarbucksSpeak, a Turing-complete coffee-ordering mini-language with a rich, free-form syntax and domain-specific jargon, allowing well-formed expressions such as: "Grande quad-shot no-room light-foam half-caf half-decaf half-lowfat half-nonfat 190-degree sugar-free vanilla medium-roast half-white chocolate half-regular chocolate Mocha Valencia with 1 pump sugar-free hazelnut and a sprig of nutmeg. Oh, and make that iced."

As one Starbucks employee put it: "More words means more money." I believe the drink above costs over seventeen dollars. You need to learn the idioms and efficiency considerations for each minilanguage to help optimize its performance.

Other widespread minilanguages include: Pizza-Ordering Language (which has many dialects but is more or less universal), Swearing Like A Drunken Sailor (which is useful when you receive the bill for your car repairs, written in the Auto Repair Theft mini-language), and of course Pig Latin, which is helpful for talking about slower co-workers ("ob-Bay's ot-nay oo-tay ight-bray, is he?"). Mini-languages are everywhere, and can be quite fun.

Regular expressions are no exception. They let you parse a log file faster than you can say: "does Python's case-insensitivity metacharacter span the entire expression, or is that just in Perl?" Like the syntax for printf's format string, regexps are a tool that will be useful in almost any language you use.

Strongly recommended. Oh, and make mine iced.