Recently bought "Regular Expressions Cookbook 2nd ed." and wanted to share my findings.

The book is divided into two parts. The first part (3 chapters) describes tools, skills and programming. The tools chapter shows you what's out there (including his own software). The skills chapter is a tutorial. It describes the parts of a regex, but just that. Although there are samples, it is regex only. No source code samples are provided here. Personally I think it may be too hard or theoretical for absolute beginners. The programming chapter shows you how to implement regexes in various languages. To be precise, the book uses .NET (C# and VB.NET), Java, JavaScript (XRegExp), PHP (PCRE), Perl, Python and Ruby.

The second part of the book (6 chapters) is the cookbook part. Every chapter shows several commonly used problems/solutions. The chapters are "Validation and Formatting", "Words, Lines and Special Characters", "Numbers", "Source Code and Log Files", "URLs and Paths" and "Markup and Data Formats". In all it shows how to use 140 regexes.

Each chapter tackles one specific task, for example "Validate Credit Card Number". The chapter starts with the problem description, followed by the solution. The solution can be extensive, depending on whether flavour specific constructs are used in that instance. After that is a discussion part, describing more about the issue, making everything clear. Sometimes a variations part is added, to show you how to add additional information to the initial problem. Finally, a see also section points you to similar/relative solutions in the book.

All in all I think this second edition is an excellent regex book. Do not buy this thinking you will get a comprehensive beginner's guide to regexes in a single language. In my opinion some basic knowledge is required, unless you are looking for the ready made solutions. The best part of this book, for me personally, is the side-by-side comparison of the different flavours. I am quite sure that this book will stay on my desk, as a good reference on how to get things done.

If you want to see more information, visit O'Reilly. If you decide to buy, make sure you have the right version (August 2012).

Recommended Answers

All 2 Replies

I just wander how it deals with important issue when you should maybe use language string processing features instead, or parser (eg html).

It does mention both. For example when describing literal text in a regex, it mentions that there are better options for replacing literal text than using a regex replace. In the last chapter when discussing parsing XML, it is also mentioned that the regex would be step one, followed by the use of a tokenizer. So, it does not state that using a regex is the holy grail. It is part of a solution. For example, in the creditcard validation example, a code example is added to show how to do a Luhn check in addition to the regex.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.