tags:

views:

882

answers:

10

I been coding in php, perl, ruby, php for around 2 years. and i still having problem with regex. Is it any tip you have for learning regex? or Great Guide?

Duplicate of http://stackoverflow.com/questions/4736/learning-regular-expressions

+8  A: 

Two spring to mind:

cletus
That site has been very helpful to me.
peacedog
+1  A: 

See the answers to this question.

Bill the Lizard
+1  A: 

i have found RegEx Cheat Sheet for .NET and RegEx Tester to be very helpful.

E Rolnicki
+5  A: 

www.regular-expressions.info and a copy of regexbuddy or powergrep or some other tool you can play around with, but online tools work well too.

I strongly recommend you learn to build patterns up. Don't solve everything at once. Takes a while before you can "see" things that way.

annakata
Tackling a problem "one piece at a time" with a regexp is often very helpful to me as well.
peacedog
I think running before you're walking is a big deal with learning regex (and not dissimilar things like xpath).
annakata
+4  A: 

An interactive tool, such as RegexBuddy, is the best way that I found to learn regular expressions.

James Sun
+2  A: 

I can recommend "Mastering Regular Expressions" by Jeffrey Friedl when you are looking for a book.

RegExBuddy is a great tool to experiment with regular expressions. It even explains them for you in human-readable language.

From the authors of RegExBuddy also comes http://www.regular-expressions.info/, a great website that explains the aspects of regular expressions in an easy way.

Sebastian Dietz
A: 

It also may be helpful if you use a tool like The Regulator to help you understand and test the regular expressions that you use and also access a repository of regular expressions created by others. It's for .Net, but there are only trivial differences between the major languages. (also it seems like there is something called Regulazy on the same web site, but I've never used it).

A: 

As stated above definitely consult a cheat sheet. I have to plug my favorite reg ex site though, regexlib.com. I learned by simply creating regex patterns I needed within the pattern tester on the site and consulting their library with the cheat sheet. Over time you need the references less, and eventually you dont need the pattern tester. I think learning regex to learn regex can be a bit daunting as it can be complex.

ccook
A: 

Another tool worth using is Expresso. All other answers are also good especially those ones that refer to regular-expressions.info.

A: 

Another approach is not just to learn regular expression syntax. You could have a look Wikipedia article for Finite State Machines to learn a little bit about the theoretical foundations and then try to understand how they work. But be aware that modern regular expression matching has a lot of features that can't be expressed with those automata.

unbeknown