Regular expression is always a tricky subject for programmers and sysadmins. When you are dealing with lot of text handling, understanding how to use Reg-ex effectively is essential. It is hard to remember the syntax of reg-ex on top of your head all the times.
Regular Expressions Cookbook is written by the Reg-Ex Jedi Master Jan Goyvaerts along with Steven Levithan.
This book with ISBN-10: 0596520689 and ISBN-13: 978-0596520687 was published by O’reilly in May 2009 and has a total of 510 pages.
Regular Expression Flavors
Following regular expression flavors are covered in this book:
- Perl: Version 5.6, 5.8 and 5.10 are covered.
- PCRE: Perl-Compatible Regular Expressions. Covers PCRE V4 – V7.
Replacement Text Flavors
Following replacement text flavors are covered in this book:
- Perl – s/regex/replace/
- PHP – preg_replace
- .NET – System.Text.RegularExpressions
- Java – java.util.regex
- Python – re module with sub function
100+ Recipe Ingredients
This cook book has over 100 recipes. Each recipe has the following:
- Problem Definition. (i.e the real-world reg-ex requirement)
- Solution in all flavors
- Examples in a specific programming language. This includes a detailed explanation of what is going behind the scenes in the regular expression.
There are total of 8 chapters in this cook book. I’ve given some high level information of what is covered in each and every chapter.
Chapter 1: Introduction to Regular Expressions
This chapters gives a high level introduction to regular expression explaining the search and replace concepts. This also explains the various utilities that are required to work with regular expressions.
Chapter 2: Basic Regular Expression Skills
Before jumping into the real world problems and solutions, this chapter explains the technical details on some of the fundamentals of regular expressions. For example:
- How to match something at the start/end of the line
- Insert match context into the replacement text.
Chapter 3: Programming with Regular Expressions
Contains recipes of how to implement various regular expressions in the programming languages that you are using. For example:
- Importing regular expression library
- Creating regular expression objects
Chapter 4: Validation and Formatting
This is an awesome chapter that contains lot of real-world examples on how to validate tons of different user inputs. For example:
- Email Address Validation
- Phone Numbers (US and International) Validation
- Date and Time Format Validation
- Alphanumeric Validation
- Postal/Zip Code Validation (US, Canada, UK)
- Credit Card Number validation
Chapter 5: Words, Lines, and Special Characters
This chapter contains recipes for intensive text manipulations. For example:
- Find Specific Word
- Find All Except Specific Word
- Remove Duplicate Lines
- Replace Repeated Whitespace with a Single Space
Chapter 6: Numbers
It is very tricky to manipulate numbers inside a regular expression. This chapter explains some basic number manipulation. For example:
- Manipulate Integer, Hex and Binary
- Strip Leading Zeros
- Manipulate Roman Numerals
Chapter 7: URLs, Paths, and Internet Addresses
This is one of my favorite chapters. This chapter is full of practical recipes for sysadmins.
- Convert URL to Links
- Validate URL
- Extract Scheme, User, Host Name, Port Number, Path, Query, Fragment from URL
- Validate Domain Name
- Match IPv4, IPv6 Address
- Strip Invalid characters from Filenames
Chapter 8: Markup and Data Exchange
Explains about regular expression manipulating while dealing with HTML, XHTML, XML,CSV and INI files. For example:
- Replace <b> with <strong> in HTML
- Convert plain text to HTML
- Match INI Name-Value Pairs
Geek Rating: 5/5 Stars
Regular Expressions Cookbook is Highly Recommended. This is hands-down the best book on the regular expression written by the Reg-Ex guru Jan Goyvaerts himself. Sysadmins and DBAs who write administrative scripts in Perl should definitely have this book as a reference. This is a must-have for programmers of all languages. When you have this book in your desk, regular expression will not look intimidating at all.