Programming Books C Java PHP Python Learn more Browse Programming Books

Sorry, this item is not available in
Image not available for
Image not available

To view this video download Flash Player

Have one to sell? Sell yours here
Tell the Publisher!
I'd like to read this book on Kindle

Don't have a Kindle? Get your Kindle here, or download a FREE Kindle Reading App.

Regular Expressions Cookbook [Bargain Price] [Paperback]

Jan Goyvaerts , Steven Levithan
4.6 out of 5 stars  See all reviews (24 customer reviews)

Available from these sellers.

This is a bargain book and quantities are limited. Bargain books are new but could include a small mark from the publisher and an price sticker identifying them as such. See details.

Free Two-Day Shipping for College Students with Amazon Student


Amazon Price New from Used from
Paperback --  
Paperback, Bargain Price, May 29, 2009 --  
Unknown Binding --  
Shop the New Digital Design Bookstore
Check out the Digital Design Bookstore, a new hub for photographers, art directors, illustrators, web developers, and other creative individuals to find highly rated and highly relevant career resources. Shop books on web development and graphic design, or check out blog posts by authors and thought-leaders in the design industry. Shop now

Book Description

May 29, 2009 0596520689 1
This O'Reilly Cookbook provides more than a hundred recipes to help programmers use regular expressions to manipulate text and crunch data. Every programmer needs a grasp of regular expressions, but their power doesn't come without problems--even seasoned users often have trouble tackling performance issues. With recipes for popular programming languages such as C#, Java, JavaScript, Perl, PHP, Python, Ruby, and VB.NET, this book offers step-by-step solutions to scores of common tasks involving regular expressions. This cookbook will help you:
  • Understand the basics of regular expressions through a concise tutorial
  • Use regular expressions effectively in several programming and scripting languages
  • Learn how to validate and format input
  • Manage words, lines, special characters, and numerical values
  • Find solutions for using regular expressions in URLs, paths, markup, and data exchange
  • Learn the nuances of more advanced regex features
  • Understand how regular expression APIs differ from language to language
  • Write better regular expressions for custom needs

Whether you're a novice or an experienced user, Regular Expressions Cookbook will help deepen your understanding of this tool. You'll learn powerful new tricks, avoid language-specific gotchas, and save valuable time with this huge library of proven solutions to difficult, real-world problems.

Special Offers and Product Promotions

Customers Who Bought This Item Also Bought

Editorial Reviews Review

Whether you're a novice or an experienced user, Regular Expressions Cookbook will help deepen your understanding of the tool. You'll learn powerful new tricks, avoid language-specific gotchas, and save valuable time with this huge library of proven solutions to difficult, real-world problems.

Searching and Replacing with Regular Expressions
Search-and-replace is a common job for regular expressions. A search-and-replace function takes a subject string, a regular expression, and a replacement string as input. The output is the subject string with all matches of the regular expression replaced with the replacement text. Although the replacement text is not a regular expression at all, you can use certain special syntax to build dynamic replacement texts. All flavors let you reinsert the text matched by the regular expression or a capturing group into the replacement. Recipes 2.20 and 2.21 explain this. Some flavors also support inserting matched context into the replacement text, as Recipe 2.22 shows. In Chapter 3, Recipe 3.16 teaches you how to generate a different replacement text for each match in code.

Many Flavors of Replacement Text
Different ideas by different regular expression software developers have led to a wide range of regular expression flavors, each with different syntax and feature sets. The story for the replacement text is no different. In fact, there are even more replacement text flavors than regular expression flavors. Building a regular expression engine is difficult. Most programmers prefer to reuse an existing one, and bolting a search-and-replace function onto an existing regular expression engine is quite easy. The result is that there are many replacement text flavors for regular expression libraries that do not have built-in search-and-replace features.
Fortunately, all the regular expression flavors in this book have corresponding replacement text flavors, except PCRE. This gap in PCRE complicates life for programmers who use flavors based on it. The open source PCRE library does not include any functions to make replacements. Thus, all applications and programming languages that are based on PCRE need to provide their own search-and-replace function. Most programmers try to copy existing syntax, but never do so in exactly the same way.
This book covers the following replacement text flavors. Refer to “Many Flavors of Regular Expressions” on page 2 for more details on the regular expression flavors that correspond with the replacement text flavors:
Perl has built-in support for regular expression substitution via the s/regex/ replace/ operator. The Perl replacement text flavor corresponds with the Perl regular expression flavor. This book covers Perl 5.6 to Perl 5.10. The latter version adds support for named backreferences in the replacement text, as it adds named capture to the regular expression syntax.
In this book, the PHP replacement text flavor refers to the preg_replace function in PHP. This function uses the PCRE regular expression flavor and the PHP replacement text flavor.
Other programming languages that use PCRE do not use the same replacement text flavor as PHP. Depending on where the designers of your programming language got their inspiration, the replacement text syntax may be similar to PHP or any of the other replacement text flavors in this book. PHP also has an ereg_replace function. This function uses a different regular expression flavor (POSIX ERE), and a different replacement text flavor, too. PHP’s ereg functions are not discussed in this book.
The System.Text.RegularExpressions package provides various searchand- replace functions. The .NET replacement text flavor corresponds with the .NET regular expression flavor. All versions of .NET use the same replacement text flavor. The new regular expression features in .NET 2.0 do not affect the replacement text syntax.
The java.util.regex package has built-in search-and-replace functions. This book covers Java 4, 5, and 6. All use the same replacement text syntax.
In this book, we use the term JavaScript to indicate both the replacement text flavor and the regular expression flavor defined in Edition 3 of the ECMA-262 standard.
Python’s re module provides a sub function to search-and-replace. The Python replacement text flavor corresponds with the Python regular expression flavor. This book covers Python 2.4 and 2.5. Python’s regex support has been stable for many years.
Ruby’s regular expression support is part of the Ruby language itself, including the search-and-replace function. This book covers Ruby 1.8 and 1.9. A default compilation of Ruby 1.8 uses the regular expression flavor provided directly by the Ruby source code, whereas a default compilation of Ruby 1.9 uses the Oniguruma regular expression library. Ruby 1.8 can be compiled to use Oniguruma, and Ruby 1.9 can be compiled to use the older Ruby regex flavor. In this book, we denote the native Ruby flavor as Ruby 1.8, and the Oniguruma flavor as Ruby 1.9. The replacement text syntax for Ruby 1.8 and 1.9 is the same, except that Ruby 1.9 adds support for named backreferences in the replacement text. Named capture is a new feature in Ruby 1.9 regular expressions.

Book Description

Detailed Solutions in Eight Programming Languages --This text refers to an out of print or unavailable edition of this title.

Product Details

  • Paperback: 510 pages
  • Publisher: O'Reilly Media; 1 edition (May 29, 2009)
  • Language: English
  • ISBN-10: 0596520689
  • ASIN: B00D9TPIS8
  • Product Dimensions: 9.1 x 7 x 1.1 inches
  • Shipping Weight: 1.4 pounds
  • Average Customer Review: 4.6 out of 5 stars  See all reviews (24 customer reviews)
  • Amazon Best Sellers Rank: #4,205,499 in Books (See Top 100 in Books)

More About the Author

Discover books, learn about writers, read author blogs, and more.

Customer Reviews

Most Helpful Customer Reviews
30 of 31 people found the following review helpful
4.0 out of 5 stars At last a Use Case based RegEx Book June 7, 2009
As much as I hate to admit it, regular expressions are hard for me. My need to use them is situation specific and I never really took the time to master them conceptually. So, when it comes time create one, I have to grope around to figure out how to meet the need at hand.

This book is really made for a person like me. The structure is problem-solution based. And, every problem is numbered in outline format. Thus, referencing back is an easy affair.

Want to know how to find bold text in an HTML file? This book will tell you how.

Want to learn how to split a sting using a regular expression? This book tells you how.

The book discusses solutions generally and in language specifics. It supports C#, Java, Javascript, Ruby, Python, PHP, Perl, VB.NET.... the entire cast of the usual characters. (No pun intended.)

The writing is clear. You can take things in a bit at a time. And, that some of the problems use those 'hard to get concepts', the topical discussions actually teach you the difficult concepts in a manner that is pretty easy to understand. Sometimes you might have to go over a section of few times to get full understanding. But the review is not a chore.

This is a good, useful book. It's helping me to become a better engineer. And believe me, I need all the help that I can get! :)
Was this review helpful to you?
17 of 18 people found the following review helpful
This excellent book goes further and deeper than many tutorials on regular expressions. You might be surprised with some of the things you'll learn from reading it.

Unlike many cookbooks, this one doesn't dive into the recipes right away. I thought this was a good call because regular expressions are a specialized topic, and most developers don't work with regular expressions on a daily basis so they probably have to be reminded of the building block concepts and syntax, and get prepared for a discussion of more advanced features. Chapter One provides a list of recommended tools for working with regular expressions. Chapter 2 is a concise but very thorough discussion of building block and more advanced regular expression concepts (e.g., possessive quantifier or atomic grouping, named capturing groups, lookahead and lookbehind, etc.), including a discussion of differences in engine implementations and feature support. Chapter 3 is a hundred-plus page tutorial on how to work with regular expressions using different programming and scripting languages, including potential gotchas and workarounds. Chapters Four through Eight contain the recipes for solving real-world problems, with tips on how to improve an initial solution's readability (e.g., use named capturing groups when possible, etc.) and/or efficiency.

I was initially skeptical about the authors' ambitious goal of covering so many regular expression flavors, thinking the discussions of differences in engine supported features might prove distracting. The book is written and organized so well, however, my fear did not materialize. In fact, I was pleasantly surprised to learn that: of the covered flavors, Microsoft's DotNet regex engine supports some of the most advanced features.
Read more ›
Comment | 
Was this review helpful to you?
11 of 12 people found the following review helpful
5.0 out of 5 stars We Have Been Waiting for This One June 9, 2009
I was getting set to write a review of this book, when I happened to visit one of the blogs I regularly read -- Coding Horror. Jeff Atwood says it all for me so please take a look at what he has to say.

If you are a serious programmer or even if you are a Web GUI design person forced to do a bit of JavaScripting like me, you are going to run into situations where using a regex engine is the appropriate tool. Regular expressions are not easy to learn and are kind of boring. They are also very powerful.

Most of us learn faster by doing -- and that most often means working from code we or someone else has done before that does something a bit like what we want to do but needs some tweaking or extending or generalizing. If you are like me, you already have a collection of regular expressions to help in this process. This book does better than that by collecting hundreds of examples together in ways that build your understanding while never getting abstract or divorced from the real problems we face.

Your shelf has a place for this book. Recommended.
Comment | 
Was this review helpful to you?
4 of 4 people found the following review helpful
5.0 out of 5 stars Jan is a regex guru! June 26, 2009
Format:Paperback|Verified Purchase
Preface: When I first dove into regular expressions two years ago, I jumped in head first with Jeffrey Friedl's classic: "Mastering Regular Expressions - 3rd Edition" (MRE3). I've read it twice so far and it is truly a masterpiece (very highly recommended). As I was learning to "think in regex", I needed some reliable tools with which to practice my newfound regex skills (I'm primarily a Windows guy). Although my text editor of choice at the time had three flavors of built-in regex support (UltraEdit32), its support for Perl compatible syntax had a few inconsistencies. A search for better regex tools led me to the EditPad Pro text editor and RegexBuddy, both from "Just Great Software" (JGSoft). These tools proved to be so well designed, bug-free and useful, that I decided to purchase the much more expensive PowerGrep (and was blown away with what I can do with that!) Armed with these tools and my newfound mastery of regular expressions (courtesy of MRE3), I now feel that I could conquer nearly any challenge from the world of text processing. I was very impressed with the quality, accuracy and attention to detail of all the JGSoft's software products, and when the author of these tools announced that he had a new book coming out on regular expressions, I pre-ordered it sight unseen. I knew it would be good. And it is. (Note that I am not affiliated in any way with JGSoft, I am just a very happy user of their software.)

Review: Jan Goyvaerts is one of the world's experts in the field of regular expressions. He is an "attention to details" and "we will serve no wine before its time" kind of guy, so I was not surprised to find "Regular Expressions Cookbook" well organized, accurate, easy to read, and having very few typos and/or grammatical errors.
Read more ›
Was this review helpful to you?
Most Recent Customer Reviews
4.0 out of 5 stars Out of the way I know regular expressions
Or I will after using this book! I use bash and powershell at work and hoping to leverage the power of regular expressions I bought this book. Read more
Published 11 months ago by Jonathon Michael Olson
5.0 out of 5 stars Express yourself!
I have several Regular Expressions books; most of them are from O'reilly.
However the others are more focused on various unix/c environments. Read more
Published 17 months ago by bernie
4.0 out of 5 stars Great primer and reference in one book
An essential skill as a programmer, regardless of language, is to understand at least the basic principles behind regular expressions. Goyvaerts Et. Read more
Published 22 months ago by Doron Katz
5.0 out of 5 stars Excellent book!
I am using regular expressions to mine historical sources. This book---and Goyvaerts' EditPad Pro---were most helpful in solving a number of very complex queries. Read more
Published on June 24, 2012 by Maxim Romanov
4.0 out of 5 stars Ask Felgall - Book Review
The authors of this book have a large amount of experience in using regular expressions with a wide variety of different languages. Read more
Published on November 23, 2011 by Stephen Chapman
2.0 out of 5 stars Would have benifited from worked examples
This is not a book for a novice to regex.

I find it difficult to understand why the publisher does not understand the importance of fully worked and downloadable code... Read more
Published on July 13, 2010 by Houston mom
5.0 out of 5 stars Very useful and clear
I have a copy of Mastering Regular Expressions by Jeffrey E. F. Friedl on my bookshelf. I bought it a long time ago to try to improve my skills at using regular expressions to... Read more
Published on January 29, 2010 by M. Helmke
3.0 out of 5 stars Regular Expressions Can be complicated
This book is not for a Regular Expressions Novice which I am. I was hoping for a book that would first explain the concepts and methodoligies before diving into examples. Read more
Published on January 3, 2010 by D. E. Lopez
5.0 out of 5 stars Learn how to format input, manage lines, find solutions for common...
Jan Goyvaerts' and Steven Levithan's REGULAR EXPRESSIONS COOKBOOK provides over 100 recipes to help blend data and text with regular expressions, offering programmers and software... Read more
Published on October 12, 2009 by Midwest Book Review
5.0 out of 5 stars For Only $30 It'll Pay For Itself In One Use
This is the kind of book one doesn't actually read (unless you're a masochist ;-), but is essential to have around. Let's face it, very few of us are good with regular expressions. Read more
Published on October 11, 2009 by Larry
Search Customer Reviews
Search these reviews only

What Other Items Do Customers Buy After Viewing This Item?

Sell a Digital Version of This Book in the Kindle Store

If you are a publisher or author and hold the digital rights to a book, you can sell a digital version of it in our Kindle Store. Learn more


There are no discussions about this product yet.
Be the first to discuss this product with the community.
Start a new discussion
First post:
Prompts for sign-in

Look for Similar Items by Category