Mastering Regular Expressions: Second Edition, by Jeffery E. F. Friedl, is an outstanding book about one of the most powerful weapons in a programmer’s arsenal. Any time you need to search or manipulate strings of text, regular expressions are the first tool that should come to your mind. Regular expressions are not only “the simplest thing that could possibly work,” but, crafted properly, they will probably be more efficient than any code you would write by hand.
This book teaches you not only the basics of regular expressions, but also their advanced features, how they work, why knowing how they work is important, and how to write regular expressions that will do what you want and exhibit the best performance. The book is very well written, very easy to read (except for some of the difficult material on optimizing expressions), and has a great mechanism for providing useful exercises that I’d love to find in more technical books. (The exercises are rare, but important, so you don’t mind trying to solve them. The question is asked in the main flow of the text, and followed by a special symbol. The answer to the exercise is in a sidebar on the next page, so you can’t easily cheat, and the symbol helps you find your place when you turn back.)
The first six chapters apply to all “flavors” of regular expressions, and thus are required reading for anyone who uses them, from the newest newbie to the most seasoned expert. The next three chapters are specifically about Perl, Java, and .NET, respectively. I must confess to having skipped the first two, since I am not currently using those technologies. The .NET section was good, and has the only reasonable explanation anywhere on how to use the cool “brace-matching” feature of .NET regular expressions. It also discusses the unique way that .NET regular expressions allow you to examine each capture of the same group, a feature that I have found very useful. Still, I wished for C# examples rather than VB.NET, and the chapter would have been better if the author had a more thorough understanding of the .NET framework.
If it isn’t already clear, this is an outstanding book that you must read. Regular expressions are incredibly powerful, and even if you already use them here and there, you need to start using them to their fullest potential.