Regular Expressions Cookbook

Category: Programming
Author: Jan Goyvaerts, Steven Levithan
All Stack Overflow 11
This Month Stack Overflow 3

About This Book

This cookbook provides more than 100 recipes to help you crunch data and manipulate text with regular expressions. Every programmer can find uses for regular expressions, but their power doesn't come worry-free. Even seasoned users often suffer from poor performance, false positives, false negatives, or perplexing bugs. Regular Expressions Cookbook offers step-by-step instructions for some of the most common tasks involving this tool, with recipes for C#, Java, JavaScript, Perl, PHP, Python, Ruby, and VB.NET.

With this book, you will:

  • 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 expressions' APIs, syntax, and behavior 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 knowledge of this unique and irreplaceable 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.


by anonymous   2019-07-21

I would strongly suggest that you write the code for both and time it. It's pretty simple to do this and you'll get an answers that is not a generic "rule of thumb" but instead a very specific answer that holds for your problem domain.

Vance Morrison has an excellent post about micro benchmarking, and has a tool that makes it really simple for you to answer questions like this...

If you want my personal "rule of thumb" then it's that RegEx is often slower for this sort of thing, but you should ignore me and measure it yourself :-)

If, for non-performance reasons, you continue to use Regular Expressions then I can really recommend two things. Get a profiler (such as ANTS) and see what your code does in production. Then, get a copy of the Regular Expression Cookbook...

... as it has loads of tips on speeding up RegEx code. I've optimized RegEx code by a factor of 10 following tips from this book.

by anonymous   2019-07-21

Not a secret regex trick but a good recommendation is the book Regular Expressions Cookbook by O'Reilly

by anonymous   2019-07-21

I am new in the world of regular expression. After googling I have found these books and places will be best reference for learning regular expression in depth. Here it is:


Regular Expression Cookbook

Regular Expression Recipes

net tuts+ Regular Expression Series:

  1. You Don’t Know Anything About Regular Expressions: A Complete Guide

  2. 8 Regular Expressions You Should Know

  3. Advanced Regular Expression Tips and Techniques

  4. Regular Expressions Cheat Sheets

  5. Regular Expressions for Dummies: Screencast Series

by anonymous   2017-08-20

This site offers a searchable library of regexs: and this regular expression cookbook contains hundreds of examples of regex matching patterns

by anonymous   2017-08-20

Also, does anyone have a very simple tutorial like RegEx for Dummies? Is it strange that I code in C++ but cannot grasp RegEx easily?

No, it's not strange. Regex mastery requires a certain mindset that doesn't come naturally. And being able to program, in C++ or any other language, doesn't seem to help--if anything, it's a handicap. There's a good tutorial here, but even the best tutorial will only get you to a pidgin level. If you really want to get your head around regexes, you need The Book.

Another problem is that there's no standard for regexes; every programming language, every framework, every IDE or text editor seems to have its own "flavor" of regex. Some have features that others don't, while some use different syntax to do the same things. That's where The Other Book comes in. Many examples of the kinds of tasks we commonly use regexes for, in several of the most popular flavors, and thoroughly explained.