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
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
i have found RegEx Cheat Sheet for .NET and RegEx Tester to be very helpful.
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.
An interactive tool, such as RegexBuddy, is the best way that I found to learn regular expressions.
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.
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).
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.
Another tool worth using is Expresso. All other answers are also good especially those ones that refer to regular-expressions.info.
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.