Great question. I learned them through osmosis over many years of looking at them in other people's code and tinkering myself. I don't remember ever going through a tutorial or reading a book. Probably not the best way to learn them as it definitely took a long time to have a good grip on them and I was missing important pieces for a long time. For example, it was only relatively recently that I learned that you can turn off "greedy" when using .* by adding a ? after it.
If I recall correctly I learnt the basics from MSDN documentation and later more thoroughly when I first came across Perl. Either of these are pretty decent choices, too. :)
I find picking an actual context is really important to keep you motivated as learning about regexps can be tedious and prone to error. Probably the most fun regexp work I've done has been with Apache's mod_rewrite - using .htaccess files of course - because it's a great feeling to master something that useful that previously just seemed like magic.
this one is incomplete but gave me a really good foundation that makes it easy to fill in gaps when I need, and most importantly gets you that "thinking in regex" result mentioned above- http://regex.learncodethehardway.org/book/
Comments
What's a good resource for learning reg exp?
Great question. I learned them through osmosis over many years of looking at them in other people's code and tinkering myself. I don't remember ever going through a tutorial or reading a book. Probably not the best way to learn them as it definitely took a long time to have a good grip on them and I was missing important pieces for a long time. For example, it was only relatively recently that I learned that you can turn off "greedy" when using .* by adding a ? after it.
How about this site? http://www.regular-expressions.info/ I just skimmed it, and I'm not a regex pro, so I can't vouch for it's quality, but it seems like a place to start. For C#, I kinda enjoyed the dotnetperls page on regex http://www.dotnetperls.com/regex.
http://www.regular-expressions.info/ is something I've stumbled across a few times in recent years, recommended by my friends to one another.
If I recall correctly I learnt the basics from MSDN documentation and later more thoroughly when I first came across Perl. Either of these are pretty decent choices, too. :)
I find picking an actual context is really important to keep you motivated as learning about regexps can be tedious and prone to error. Probably the most fun regexp work I've done has been with Apache's mod_rewrite - using .htaccess files of course - because it's a great feeling to master something that useful that previously just seemed like magic.
What you want is to achieve a level where you can start thinking in regexp.
Eg: /^([a-z]*)$/ this translates into my brain to: a string that starts with a capture group of 0-N characters between a-z and also ends with it.
Then it's really easy.
this one is incomplete but gave me a really good foundation that makes it easy to fill in gaps when I need, and most importantly gets you that "thinking in regex" result mentioned above- http://regex.learncodethehardway.org/book/