I'd like to improve my regex knowledge. Are there any exercises/tools that you wolud recommend?

+2  A: 

Reading about them is fine, but actually getting hands on experience with a tool is really helpful.

Try the Regulator - http://weblogs.asp.net/rosherove/pages/tools-and-frameworks-by-roy-osherove.aspx

Joe R
+11  A: 

I highly recommend reading Mastering Regular Expressions. It lives up to its name.

This book was the first thing that came to my mind.
@J.J. Same here. That is an excellent book
Eric Haskins
Nice link to anything but the book you mention. Besides, this answer was given five minutes prior to yours and the link to the book is correct.
Seems like you can't hear about this subject without having the owl mentioned.
Downvoted for stealth hyperlinking to your blog instead of the book you reference.
Michael Carman
What's up with the link?
That's awesome. I didn't realize that there's some web/SO etiquette where you shouldn't link to your own site. If you can't shamelessly self-promote on this interweb, what good is it?
At least link to the book in question. Your blog entry has nothing to do with the book.
Andy Lester
Fixed the link in question. It was a clipboard mistake on my part. Sorry!
+9  A: 

Start using RegExBuddy!

+14  A: 

Here are some good resources:



regexlib is the way to go!
Yeah, I just snagged an email validator expression yesterday. Thanks, anonymous contributor of said expression!
I like www.regular-expressions.info it is great. Every once in a while when I want to use a more obscure expression I refer to this site....
+2  A: 

Perl + Roberts Perl Tutorial are the source of most of my regex ability.

Paul Nathan
+12  A: 

regular-expressions.info is an excellent site, and RegexBuddy is a great visualizing tool.

Forgotten Semicolon
+4  A: 

As Joe90 mentions, reading about them takes you a long way ;)

Personally I find http://www.regular-expressions.info/ a great resource for regex.

+4  A: 

Practice, practice, practice. I've always found Perl's manual page on regular expressions to be an excellent reference for all the common and POSIX regex symbols and commands.

Also try http://perldoc.perl.org/perlretut.html
Brad Gilbert
+4  A: 

Besides those already mentioned, you can try the Regex Coach. I've heard good things about it.

+6  A: 

To master them, don't stop at reading about them. Go down the list of posts tagged regex and start solving the problems. Don't peek at the answers until you're ready.

+29  A: 
lol, i clicked this topic just to post the link to this book.. too fitting to the question :P
That picture is begging for a macro/'shop.
Rob Howard
+4  A: 

Now we've given lots of pointers for learning more about regular expressions, it's probably worth quoting Jamie Zawinski:

Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.

Part of learning about regular expressions is learning when not to use them (and when they're appropriate).

It's cute to say that, but there are cases where using a Regular Expression really is the correct answer - especially in simpler use cases where the regular expression is fairly understandable.
John Fiala
Excellent. I have adopted this as a heuristic, or rule of thumb if you don't like the pedantic sound of the word 'heuristic'.
John, I thought it was obvious (expanded now) that I wasn't saying you should *never* use them. There are times when they are just the right tool. Unfortunately, that's also a smallish subset of the times people try them.
Yeah, you're misunderstanding the quote. I believe he said that during an anti-perl rant (possibly because it was difficult back in 97 to initiate a regex function in perl). He wasn't saying don't use it.
+4  A: 

As simon pointed out. The most important part in mastering Regex is when NOT to use regex but that skill will come eventually. Till then use regex when you're doing Word finds or in your fave texteditor or in Excel. Anywhere that gives you that option, take it till you get a good handle on it.

Also, learn about these concepts fairly early on.

  • greedy
  • lazy
  • what the difference between "." and "\w"
  • "\b"
  • the short-hand character classes ("\s", "\d", etc)
+5  A: 

I keep a copy of the Regular Expression Pocket Reference at hand while I work - it gives me the short info I need about the use of RegEx in about a dozen languages at hand.

John Fiala
This appears to be out of print.
Clay Nichols
The next edition is in print, at http://oreilly.com/catalog/9780596514273/index.html.
John Fiala
+8  A: 

Best way to master regular expressions is to use them in your day to day work. Use a regex aware editor. I recommend NotePad++. Use the find and replace functionality with regex enabled.

You need to know just the basics to start off. Words, characters, numbers, white spaces. They are quite easy to remember. You don't get everything right the first time. But you will learn every time you try it.

Remember, unless you use it regularly, you will probably forget regex in couple of weeks.

+5  A: 

Expresso is a pretty good, free RegEx utility:


And a Regular Expressions Cheat Sheet which comes in handy:


Gordon Bell
Gordon, those are both excellent suggestions. I wish I could vote twice :-)
Clay Nichols
+2  A: 

I learned about them by learning Perl, and using it to create a configuration file parser. If you wanted to do something similar these days I would suggest Ruby, which has a similar hook for RE in it. Once I learned the basics, I found many of the tools I'd been using had great RE support, if you knew to use it. It is really very powerful.

I highly recommend the Regular Expressions Pocket Reference that others have mentioned. It will be much simpler to keep around to look up something quickly, as you will need to do. Not to mention that many applications have slightly different ways of implementing some parts of it (ie, whether you should have to backslash escape parenthesis).

If you do much text processing, I recommend learning RE. You will appreciate it.

+2  A: 

Make sure you understand the basics. You can get this from a variety of sources (depending on your choice of regex flavor).

You can play around with them on something like this.

Jeremy Cantrell
+2  A: 

You can never master regular expressions. Just when you think you have you realise it is the regular expressions who have mastered you.

Not to mention the fact that Perl's RegExs keep getting new, useful features.
Brad Gilbert
In Mother Russia, regular expressions master You!
+1  A: 

Fix bugs in Jeff Friedl's book before he does. Until you do that, you haven't mastered regular expressions.

Windows programmer
+2  A: 
Rob Howard
Redundant answers is not a problem.
Is each answer accepted 0 or more times, or 1 or more times?
Windows programmer
Subtle 'shop not as funny as originally hoped. D:
Rob Howard

If you are working in .NET I recommend this site to visualize your results as well as see how to set up your code.


I found that learning about how they were implemented under the hood really helped. Actually it was studying languages and compiler design that I first encountered regexes. Knowing where they come from, and how they relate to grammars, DFAs, lexers, etc I think is a real help. It especially helps with debugging, since you can get into the mind of the regex so to speak.



is something i found after looking through some other sites