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.
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...
http://msdn.microsoft.com/en-us/magazine/cc500596.aspx
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...
http://www.amazon.co.uk/Regular-Expressions-Cookbook-Jan-Goyvaerts/dp/0596520689/ref=sr_1_1?ie=UTF8&s=books&qid=1259147763&sr=8-1
... 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.
Not a secret regex trick but a good recommendation is the book Regular Expressions Cookbook by O'Reilly http://www.amazon.com/dp/0596520689
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-Pocket-Reference
Regular Expression Cookbook http://www.amazon.com/Regular-Expressions-Cookbook-Jan-Goyvaerts/dp/0596520689/ref=sr_1_4?s=books&ie=UTF8&qid=1346331948&sr=1-4&keywords=regular+expression
Regular Expression Recipes
net tuts+ Regular Expression Series:
You Don’t Know Anything About Regular Expressions: A Complete Guide
8 Regular Expressions You Should Know
Advanced Regular Expression Tips and Techniques http://net.tutsplus.com/tutorials/php/advanced-regular-expression-tips-and-techniques/
Regular Expressions Cheat Sheets
Regular Expressions for Dummies: Screencast Series
This site offers a searchable library of regexs: and this regular expression cookbook contains hundreds of examples of regex matching patterns
Answering the second part of your question:
As far as books are concerned, Regular Expression Cookbook by O'Reilly is fantastic. The first few chapters pretty much cover all the basics, and then some. The rest of the book is concrete examples.
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.