Regular Expressions Cookbook

About the Book

If you're a programmer, you've undoubtedly needed to search or manipulate text at some point. Regular expressions provide a flexible and concise means to complete most such tasks. However, their power does not come without its problems. Regular expression syntax can be challenging for newcomers, and even seasoned users often have trouble tackling performance issues, the nuances of more advanced features, and matching precisely what they intend and nothing more. Additionally, while most regular expression flavors share a common set of basic syntax, more advanced features and APIs commonly differ. To help you overcome these challenges, this book provides 146 recipes written for today's most popular programming languages, including C#, Java, JavaScript, Perl, PHP, Python, Ruby, and VB.NET. In addition to providing regular expressions you will find useful, this book will deepen your understanding of the field and help you write better regular expressions for custom needs. If you've been using regular expressions for years, this book will help you advance to the next level. You'll learn powerful new tricks, steer clear of flavor-specific gotchas, and save valuable time with this huge library of proven solutions to difficult, real-world problems. The contents include a regular expression tutorial; using regular expressions in programming and scripting languages; validating and formatting input; words, lines, and special characters; source code and log files; numerical values; URLs and paths; markup and data interchange.

Endorsements for The Second Edition

"Regular Expressions Cookbook manages to be simultaneously accessible and almost ridiculously comprehensive. The problem, solution, discussion format lets you learn regular expressions as needed, without being overwhelmed by their Swiss army knife complexity. I consider myself a fairly advanced regex user and about 50 pages in I've already had three big 'oh, wow, I didn't realize that' moments."—Jeff Atwood, @codinghorror

"Understanding Regular Expressions is a skill that every software developer should have. And yet, due to their complex nature and terse syntax, Regular Expressions reamin a mystery to far too many developers. Luckily, Steven Levithan and Jan Goyvaerts have shed a powerful light on the subject. Using eight different programming languages, Levithan and Goyvaerts examine the ins-and-outs of Regular Expression syntax, providing everything from introductory tutorials for beginners to advanced solutions that will stretch the skills of even the most experienced RegEx ninja. Regular Expressions are a timeless technology; and, the Regular Expression Cookbook will surely prove to be a consistent source of both information and inspiration for years to come."—Ben Nadel, www.bennadel.com

"After a very good, fast paced introduction to regular expressions, the following chapters contain various detailed recipes for solving particular tasks, ranging from the simple to the absolutely scary. Many recipes are not just about regular expressions, but also about interesting stuff like telephone numbers or XML."—Nikolaj Lindberg, Computational Linguist, STTS Speech Technology Services

Feedback from Readers of The First Edition

"I received my copy of the regex cookbook (pre-ordered) and LOVE IT! It has completely changed my ability to understand regex and has revolutionized my day to day tasks. Your writing is brilliant, thank you."—Josh Wolfer, 29 June 2009, California, USA

"I'm really enjoying Regular Expressions Cookbook... got my copy last week and I'm finding interesting and different perspectives on problems I solve everyday in Perl... I've been using Perl and regexes for almost a dozen years now, and I have many of the same regex solutions as the cookbook, but every once in a while I'm seeing another way to do something! TIMTOWTDI! Thanks for a good contribution to the regex literature... the Cookbook goes well on my nightstand right next to Jeff Friedl's Mastering Regexes. BTW, I'll be getting another copy of the Cookbook to leave at the office for my team's reference."—Howard Maher, 15 June 2009, Texas, USA

Excerpt from Jeff's review Regular Expressions for Regular Programmers: "Although my expectations were high, I think this book has exceeded even the loftiest expectations I had. It is outstanding. Regular Expressions Cookbook manages to be simultaneously accessible and almost ridiculously comprehensive."—Jeff Atwood, 8 June 2009, California, USA

Download Regular Expressions and Code Snippets

You can download the code samples from the 2nd edition of Regular Expressions Cookbook. This HTML file contains all the blocks with regular expressions and source code from the book, along with the titles of the chapters, recipes, and sections that they are found in. If you have purchased the book, you can use this file to easily copy and paste the regular expressions and source code snippets.

Even if you purchased the ebook, you may prefer to use this file. The regexes in the ebook are formatted with line breaks and gray dots for spaces to make them easier to read in print. The HTML file does not use such formatting, so you can copy and paste them directly. This means that some very regexes will run beyond the edge of your browser window.

About the Authors

Jan Goyvaerts runs Just Great Software, where he designs and develops some of the most popular regular expression software. His products include RegexBuddy, the world's only regular expression editor that emulates the peculiarities of 15 regular expression flavors, RegexMagic, a tool for generating regular expressions based on sample text and high-level patterns, and PowerGREP, the most feature-rich grep tool for Microsoft Windows.

Steven Levithan works at Facebook as a JavaScript engineer. He has enjoyed programming for nearly 15 years, working in Tokyo, Washington D.C., Baghdad, and Silicon Valley. Steven is a leading JavaScript regular expression expert, and has created a variety of open source regular expression tools including RegexPal and the XRegExp library.

Product Details

Second EditionFirst Edition
Paperback: 612 pages
Publisher: O'Reilly Media, Inc. (August 2012)
Language: English
Print ISBN-10: 1-4493-1943-2
Print ISBN-13: 978-1-4493-1943-4
Print list price (USA): $49.99
Ebook ISBN-10: 1-4493-2747-8
Ebook ISBN-13: 978-1-4493-2747-7
Ebook list price (USA): $39.99
Paperback: 510 pages
Publisher: O'Reilly Media, Inc. (May 25, 2009)
Language: English
Print ISBN-10: 0-596-52068-9
Print ISBN-13: 978-0-596-52068-7
Print list price (USA): $44.99
Ebook ISBN-10: 0-596-80278-1
Ebook ISBN-13: 978-0-596-80278-3
Ebook list price (USA): $31.99

Order Now!

All order links are for the 2nd edition.

Order Regular Expressions Cookbook from Amazon.com. Free shipping to the USA.

Order Regular Expressions Cookbook from Amazon.ca. Free shipping to Canada.

Order Regular Expressions Cookbook from Amazon.co.uk. Free shipping to the UK and Ireland.

Order Regular Expressions Cookbook from Amazon.fr. Free shipping to France, Monaco, Luxembourg, and Belgium.

Order Regular Expressions Cookbook from Amazon.de. Free shipping to Germany, Austria, Switzerland, Luxembourg, Liechtenstein, Belgium, and The Netherlands.

Order Regular Expressions Cookbook from Amazon.co.jp. Free shipping to Japan.

Kindle Edition

All Kindle links are for the 2nd edition.

Buy The Kindle Edition of Regular Expressions Cookbook from Amazon.com.

Buy The Kindle Edition of Regular Expressions Cookbook from Amazon.co.uk.

Buy The Kindle Edition of Regular Expressions Cookbook from Amazon.fr.

Buy The Kindle Edition of Regular Expressions Cookbook from Amazon.de.

Translated Editions

The first edition of Regular Expressions Cookbook has been translated into various languages.

German

Gebundene Ausgabe: 519 Seiten
Verlag: O'Reilly (28. Dezember 2009)
Sprache: Deutsch
ISBN-10: 3897219573
ISBN-13: 978-3897219571
Preis: EUR 49,90

Order Reguläre Ausdrücke Kochbuch from Amazon.de. Kostenlose Lieferung nach Deutschland, Österreich, Belgien, Liechtenstein, Luxemburg, Niederlande und die Schweiz.

Order Reguläre Ausdrücke Kochbuch from Amazon.co.uk. Free shipping to the UK and Ireland.

Order Reguläre Ausdrücke Kochbuch from Amazon.fr. Free shipping to France, Monaco, Luxembourg, and Belgium.

Russian

Buy Регулярные выражения. Сборник рецептов from books.ru.

Japanese

Buy 正規表現クックブック from Amazon.co.jp.

Korean

Buy 한 권으로 끝내는 정규표현식 from the publisher Hanbit Media, Inc.

Portuguese

Buy Expressões Regulares Cookbook from the publisher Novatec

Czech

Buy Regulární výrazy Kuchařka programátora from cpress.cz.

The Czech translation is an abridged translation. It has only 7 chapters compared to 8 with the original English edition. The last chapter, "Markup and Data Interchange", was omitted. This chapter has examples on using regular expressions on HTML and XML files and demonstrates some more complex regex techniques. All the other chapters were translated completely.