Regular Expression Recipes: A Problem-Solution Approach

by Apress

$34.99
66% off
buy from amazon.com
Average Rating: * * * * -
Sales Rank:288815 (lower is better)
Price as of:11/21/2008 8:18:07 AM MST
Price Used:$6.07
Shipping:Free Shipping on most orders over $25*
Availability:Usually ships in 7 to 13 days
Label:Apress
Pages:289
Binding:Paperback
Publication Date:2004-12-06
Published By:Apress
ASIN:159059441X
Category:Book

Authors

Editorial Reviews and Product Descriptions

Product Description

...a handy book to have. I wouldn't hesitate to recommend it.

— Raymond Lodato, Slashdot Contributor

This book is a good reference for those more interested in simply getting the job done.

— Jack Herrington, Code Generation Network

Regular Expressions are an essential part of programming, but they sure are hard to come to grips with, aren't they? Fortunately, we have the answer for you! Regular Expression Recipes provides you with all the open source regular expressions you'll ever need, and explains how to use each one. This way, you can learn by example, rather than muddling through countless pages of explanatory syntax.

Author Nathan A. Good includes syntax references only when necessary. Languages covered include Perl, PHP, grep, vim, Python, and shell. Web and applications developers, and system administrators will find the examples both accurate and relevant. And this book acts as a useful reference to keep handy for those moments when an answer is needed fast.

Customer Reviews

Regular Expression 101 - Reviewed on 2006-11-01
* * * *

If you have trouble understanding regular expressions then this book will clear all that up. This was an invaluable resource for quickly adding some regulard expressions to a project I was working on. Expression strings can be tricky to undertand at times, this book gave great details into what each piece of the expression string would match on. This resource saved my team a few hours of research, trial and error time, by giving us a great basis to start from. Another excellant resource to have on you shelf.
Too much source code, not enough regular expressions - Reviewed on 2005-08-25
* * *
12 customers found this review helpful, 2 did not.

When I saw the title of this book, I was excited at the prospect of a book filled with detailed regular expression examples. Unfortunately, it didn't pan out that way.

Spread over 285 pages, the book lists 100 tasks that you can accomplish with regular expression. As the solution, the author not only gives a regular expression, but also a complete source code snippet in Perl. Most of the recipes also show the same solution (using the same regular expression) in a different programming language. Many recipes have solutions in PHP or Python. Some also have solutions for Vim (a UNIX text editor) and UNIX shell scripting.

Obviously, the examples have a heavy bias towards UNIX and open source. If you're a Windows programmer, you may want to look at "Regular Expression Recipies for Windows Programmers" instead. It's essentially the same book, with almost the same list of recipes, but with the examples redone in C# and VB.

Each recipe also has a "how it works" section, essentially transcribing the regular expression in English.

Most of the recipes solve rather basic problems, organized in six chapters. The first, "Words and Text", deals with finding blank lines, repeated words, words at the start or end of a line, etc. The "URLs and Paths" chapter has examples for finding URLs and file paths, and extracting bits from them. The "CSV and tab-delimited files" has a few recipes for converting between the two and extracting fields.

The "Formatting and Validating" chapter shows how to validate numbers, currency, dates, phone numbers, addresses, etc. The "XML and HTML" chapter has recipes for matching and replacing tags and attributes. Finally, "Coding and Using Commands" has some recipes for manipulating source code files, and for parsing the results of various UNIX system commands.

The book would have been a better deal if it had focused on regular expressions, and left out the many lines of Perl source code. Not to mention the fact that many examples have equivalent source code listings for PHP and/or Python as well. Without the source code, a book of the same size could easily contain 250 examples. That would have made it far more useful for programmers who know how to program, but aren't well-versed in regular expressions.

As it is, I can only recommend this book to people who are not only new to regular expressions, but also relatively new to programming. The book does contain many recipes that solve basic problems you're likely to encounter when writing scripts for a web site in Perl, PHP or Python. If you happen to use one of these languages, and are looking for a cookbook approach, you'll certainly find the book useful.

But don't expect to really learn how regular expressions work from this book. (...)
Nice bridge between learning and doing... - Reviewed on 2005-04-11
* * * *
1 customer found this review helpful, 1 did not.

Regular expressions are very powerful, but extremely cryptic to read and/or understand. Nathan A Good's book Regular Expression Recipes - A Problem-Solution Approach (Apress) does a good job in showing you practical applications of regular expressions in multiple languages.

Chapter List: Words and Text; URLs and Paths; CSV and Tab-Delimited Files; Formatting and Validating; HTML and XML; Coding and Using Commands; Index

Good basically takes a number of sample problems, like finding similar words or validating U.S. dates, and then shows how the task can be done in various languages using regular expressions. Most of the solutions have two or more language examples: Perl, PHP, Python, Vim, GNU grep, or sed. In addition to showing you the statement that will do the task, he also gives a brief explanation on how the statement works and why it does what it does. This definitely wouldn't be the book you'd get in order to learn about regular expressions, but it'd be the perfect bridge between learning and doing. As you can tell by the list of languages, you probably won't find this as helpful if you're more interested in Java or JavaScript regular expression processing. But even then, you'll at least get the general idea of how a regular expression could be written to do a certain task, and it may spark your imagination on what it would take to apply that technique to your language of choice.

Nice practical book, and one that would be useful for anyone who lives in the regex world...
A cookbook of useful regular expressions for Perl and more. - Reviewed on 2005-03-18
* * * *
9 customers found this review helpful.

If you spend time working writing applications that have to do pattern matches and/or replacements, you know about some of the intricacies of regular expressions. For many people they can be an arcane hodgepodge of odd characters, but they don't have enough time (or interest) to really understand how to code them. Nathan A. Good has written Regular Expression Recipes: A Problem-Solution Approach for those people. In its relatively slim 289 pages, he offers 100 regular expressions in a cookbook format, tailored to solve problems in one of six broad categories (Words and Text, URLs and Paths, CSV and Tab-Delimited Files, Formatting and Validating, HTML and XML, and Coding and Using Commands).
Regular expressions are not restricted to just the Perl or shell environments, so Nathan offers variations for Python, PHP, and VIM as well. In most cases the translation is relatively straight-forward, but in a few cases a different environment may have (or lack) additional facilities, prompting a different expression to do the same task.
Before you even read chapter 1, Nathan provides a quick summary course on regular expressions, with detail given to each of the five environments you might utilize. He has written the syntax overview in a highly-readable format, making it easy to understand the gobbledy-gook of the most bizarre concoctions you might encounter.
In each chapter, Nathan gives examples of how to find single words, multiple words, and repeated words, along with examples of how to replace various detected strings with others. In each case he gives an example of its use for each platform, followed by a bit-by-bit breakdown of how it works. Not every environment is given on every example, and in many cases the "How It Works" section refers to the first one, as most REs are identical between the platforms.
First, I must admit that there are a number of useful solutions provided, especially for someone who is concerned with application and web development. However, I did feel a little cheated by the fact that several chapters covered essentially the same task, with only minor variations. It almost seemed as though the author was trying to pad out the solution count to the magic number 100. A simple example: three solutions in chapter one cover (a) replacing smart quotes with straight quotes, (b) replacing copyright symbols with the (c) tri-graph, and (c) replacing trademark symbols with the (tm) sequence. Did we really need three separate chapters for that? I don't think so.
Another quibble revolves around some of the coding of the expressions. Nathan has made liberal use of the non-capturing groups to insure only the items that needed replacement were captured. While a worthy idea, in some cases the expression may have been simplified for understanding. Another issue is a slight error in searching for letters. In a number of expressions, Nathan uses [A-z] to capture all letters. Unfortunately, the special characters [, \, ], ^, _, and ` occur between upper-case Z and lower-case a, making it match too much. Either [[:alpha:]] or [A-Za-z] should have been used.
Despite a couple of quibbles, Regular Expression Recipes does provide a useful compendium of solutions for common problems developers face. Presenting the information in a cookbook fashion, along with insuring that those using something other than Perl don't have to sweat translating the expressions to their target language, makes this a handy book to have. I wouldn't hesitate to recommend it.
One of the best guides available - Reviewed on 2005-02-09
* * * * *
2 customers found this review helpful, 2 did not.

Whether you are using Perl, PHP, Python, grep, sed, or any other program that uses regular expressions you will eventually have a problem trying to figure out just how to do something. That is where this book comes in handy. If you need to resolve a peculiar programming problem then this is the book you will want by your side. If the expression doesn't work, or doesn't provide the correct output this is the best place to turn to figure out what is going on. Or, if you want to do something different then you might want to turn here first to look for ideas on how to attack the problem. Since this is a problem and solution oriented approach it provides a solution in Perl, PHP, Shell Script, and Vim. Regular Expression Recipes: A Problem-Solutions Approach is a highly recommended resource and does an excellent job of describing in plain English how to define the problem, how to work on it, and how to get the results you want. This is the ultimate guide to regular expressions.
Read More Customer Reviews »
Go To Amazon Product Page

* - See Amazon Product Page for shipping and pricing details.


Book Subjects