views:

159

answers:

4

Does anyone know of a good set of tutorials for regular expressions? Particularly in a Textmate context? I am familiar with regular expression syntax, and the basic concepts. Even own a copy of Jeffrey Friedl's book "Mastering Regular Expressions" and read though the Perl parts.

What I am looking for are some high quality demonstrations of regex usage with a clear explanation of the pattern being matched and how to decompose the regex syntax. I want to take my regex fu to the next level. I want to be able to think in regex but I need something tangible to practice with to cement the knowledge in my head. What would be helpful is some text and code examples to work through with specific tasks and associated regex solutions, preferably functional in a Textmate context. The place where I find I want to use it most is in the text editor. So the ability to do powerful search and replace functions is desired. And sometimes just search. So the ability to quickly write partial regex that narrows the results down and then parse through a complex document iteratively would be handy.

Perhaps an interactive demo where the patterns are revealed as you type the regex. And some useful patterns and examples to test and play with. Perhaps some regex flash cards or a simple regex based game.

For you regex gurus out there what did you do to really cement your understanding of regex?

+2  A: 

I'm new to regex's, but needed to learn them for C#. I found a quick tutorial that went in depth about regex's in a simple way. It won't have you writing regex's that can validate an email (which is hard if you've ever tried), but it was a great intro.

Lucas McCoy
+4  A: 

The canonical site is regular-expressions.info. It contains a great in-depth tutorial, lots of real-world regex examples, and a comprehensive reference for the difference between regex flavors. Also, Jan Goyvaerts' and Steven Levithan's new book "Regular Expressions Cookbook" is highly recommended.

I personally have derived most of my regex knowledge from using RegexBuddy which is a great interactive tool for constructing, analyzing, debugging, and using regexes. I even switched editors from UltraEdit to EditPadPro because of its awesome regex features.

Sorry if I'm coming across as a Jan Goyvaerts fanboy, but Jeff Atwood would probably agree.

Tim Pietzcker
Yes, I have the Cookbook, and it seems to be exactly what you're looking for: it sets out a problem, solves it with a regex, then explains the solution in great detail. +1 for EditPad Pro, too; its regex support is just amazing.
Alan Moore
+2  A: 

Regex-fu, eh? In that vein: "Cry in the dojo, laugh on the battefield!"

Invest some time studying theoretical computer science, especially automata theory. Introduction to Automata Theory, Languages, and Computation is the textbook I used as an undergrad, and I recommend it highly!

"Pure" regular expressions correspond to deterministic finite state automata, and you'll want to develop a strong intuition for what they are, and are not, capable of.

Context-free grammars and methods for parsing them are something else you'll want to study carefully. This will help you know when to "upshift" to a more powerful paradigm when it's called for, rather than trying to shoehorn every text processing task into a regex exercise.

Jim Lewis
+1  A: 

Take a look a Expresso. It's free and shows the regular expression as a tree structure. It also makes it easy to experiment with regular expressions.

Leander