≡ Menu

Book Review: Regular Expressions Cookbook By Jan Goyvaerts and Steven Levithan

Regular Expressions Cookbook ReviewRegular 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.
  • Java
  • Javascript
  • .NET
  • Python
  • Ruby

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
  • Javascript
  • Python – re module with sub function
  • Ruby

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.

Add your comment

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

Comments on this entry are closed.

  • Phaniraj July 29, 2009, 1:57 am

    I have the book. Bible for regex.

  • Malaka July 29, 2009, 5:09 am

    Gr8 book. All you need to know about regex

  • david July 30, 2009, 11:38 am

    Great book.

    Thanks.

  • Ramesh Natarajan August 2, 2009, 5:06 pm

    @Phaniraj, @Malaka, @David,

    Thanks for your comment. Great to hear your feedback on this book.

  • Rahul Shelke August 2, 2009, 10:30 pm

    Hi Ramesh Natrajan,
    How are you?…hope you fine
    I have registered on geekstuff site but i stil ldidnt get the password for online reading different articales. Could you please provide me password on above mentioned e-mail id?..
    Thanking you for u help.

    Rahul Shelke

  • Phu September 28, 2009, 3:12 am

    Thanks for a very well written review.