Regex Guru

Friday, 29 May 2009

Regular Expressions Cookbook in PDF Format

Filed under: Regex Cookbook — Jan Goyvaerts @ 15:06

O’Reilly’s website lists Regular Expressions Cookbook in PDF format for $31.99. That’s less than the list price of $44.99 for the print version, but just a bit more than the discounted price of $29.69 that Amazon.com is asking for the print version right now. But if you want instant access or you live in the tropics where it takes 3 weeks and costs $10 to receive anything from Amazon, and you don’t have a Safari subscription, the PDF is a good deal.

Thursday, 28 May 2009

The True Story About The Rat

Filed under: Regex Cookbook — Jan Goyvaerts @ 11:29

I previously blogged about the rat on the cover of Regular Expressions Cookbook. Turns out it is not really a rat, if you get technical about such things. In fact, it’s not a rodent at all. The colophon in the book has this to day:

The image on the cover of Regular Expressions Cookbook is a musk shrew (genus Crocidura, family Soricidae). Several types of musk shrews exist, including white- and red-toothed shrews, gray musk shrews, and red musk shrews. The shrew is native to South Africa and India.

While several physical characteristics distinguish one type of shrew from another, all shrews share certain commonalities. For instance, shrews are thought to be the smallest insectivores in the world, and all have stubby legs, five claws on each foot, and an elongated snout with tactile hairs. Differences include color variations among their teeth (most noticeably in the aptly named white- and red-toothed shrews) and in the color of their fur, which ranges from red to brown to gray.

Though the shrew usually forages for insects, it will also help farmers keep vermin in check by eating mice or other small rodents in their fields.

Many musk shrews give off a strong, musky odor (hence their common name), which they use to mark their territory. At one time it was rumored that the musk shrew’s scent was so strong that it would permeate any wine or beer bottles that the shrew happened to pass by, thus giving the liquor a musky taint, but the rumor has since proved to be false.

The cover image is from Lydekker’s Royal Natural History.

Wednesday, 27 May 2009

Regular Expressions Cookbook Has Been Published

Filed under: Regex Cookbook — Jan Goyvaerts @ 11:29

I just heard from my editor at O’Reilly that Regular Expressions Cookbook, written by Steven Levithan and me, is now shipping. When I write this, Amazon.com still lists as a pre-order with a June 4 release date. I’m sure they’ll fulfill all pre-orders by that date, so don’t wait with buying your own copy! If you use one of the links below to order, Amazon will pay me an affiliate commission, which will pretty much double the slice I get from what you pay for the book. I’ve listed the names of the countries to which Amazon offers free shipping. The list price of the book is US$ 44.99. The various Amazon sites offer different discounts, up to 34%, with free shipping to various countries:

The book covers the regular the regular expression flavors .NET, Java, JavaScript, Perl, PCRE, Python, and Ruby, and the programming languages C#, Java, JavaScript, Perl, PHP, Python, Ruby, and VB.NET. After a quick introduction, the book starts with a detailed regular expression tutorial which equally covers all 7 regex flavors. That chapter is followed by a detailed guide how to implement regular expressions in your source code, again covering the 8 programming languages equally. These chapters too are presented in cookbook format. You can easily pick out the task you want to accomplish when creating a regular expression of your own, and when you want to do something with a regex in your source code. While there’s some repetition, particularly in the programming guide, because of our goal of equal coverage, the benefit is that you can easily skip the parts on programming languages you’re not interested in, in true cookbook style.

The remaining chapters, over half of the book, present real-world problems, and how to solve them with regular expressions. These problems range from very simple problems and everyday regex tasks, to some complex problems that stretch the limits of what you can do with regular expressions, but show how a regex-based solution is often much quicker than doing the same in procedural code, particularly if you only need to do the job once. All the real-world problems also have solutions for all regex flavors. A few solutions add procedural code to make up for missing regex features, such as JavaScript lacking lookbehind. The book does not cover regex flavors with limited features such as the venerable POSIX standard. We didn’t want to put those flavors on the cover and then disappoint readers by saying “can’t be done with this limited flavor” for half of the recipes in the book.

If you use regular expressions with the latest versions of PowerGREP, EditPad Pro or AceText, you can use pretty much any of the regular expressions presented in the book. These products use a custom regex flavor that is a fusion of the features found in the flavors covered in Regular Expression Cookbook. RegexBuddy 3 emulates all the flavors in the book. Older versions of these products are based on PCRE 4, without Unicode support.

Regular Expression Cookbook targets people with regular expression skills ranging from zero to upper intermediate, who want to learn about regular expressions for the first time, or sharpen their skills to become experts. Except for the chapter on programming languages, most of the recipes in the book don’t require programming skills to implement the solutions in EditPad Pro, PowerGREP, or any other text editor or search tool that uses one of the book’s regular expression flavors. The programming chapter assumes you’re familiar with all the basic features and syntax of your programming language, but it doesn’t assume you’ve ever used regular expressions in your source code.

While the jury has only just received their copies of the book, I dare say that Regular Expression Cookbook is the most practical book on regular expressions to date, filled with lots of detailed information about flavor-specific and language-specific features or issues glossed over by many other books and online articles.