My applications frequently use Regex for input validation.
Most of the Regex values that I need are pretty common (email address, basic types, etc). What is a good place to both learn about Regex creation and find common Regex patterns?
My applications frequently use Regex for input validation.
Most of the Regex values that I need are pretty common (email address, basic types, etc). What is a good place to both learn about Regex creation and find common Regex patterns?
I like the (Python Regular Expression Howto)[http://www.amk.ca/python/howto/regex/] it provides a (reasonably) quick reference as well as some interactive examples showing regexes in action.
Obviously, this is a little python centric, though python uses a regex syntax shared by Perl, Java, etc.
I use this one a bunch: http://www.regular-expressions.info/
I have this cheat sheet pinned to my cubicle wall...
^ Start of String
$ End of String
. Matches any single char, but not line breaks
- Indicates a range. "0-3" will match 0,1,2, or 3
[] Character class. "gr[ae]y" will match "gray" or "grey"
| Alternation (or) "thisPattern|thatPattern" will match either.
? Preceeding optional. "colou?r" will match "color" or "colour"
* Matches the preceeding token 0 or more times. "a*" will
match "", "a", "aaa", or "abc"
{} Number of specific matches "(abc){2}" will match "abcabc" but not "abcdabc"
() Grouping operator
and a program called RegexDesigner to test them.
I like the explanations at http://www.regularexpressions.info
http://regex.larsolavtorvik.com/ There's this cool tool in which you can test your regular expressions online as implemented in different languages (PHP/Perl/JavaScript). It's nice for tesing. For each language you have a cheatsheet reference right beside the tool. It's great because it's both a cheatsheet and a testing tool. I like to craft my regular expression in there.
http://www.regular-expressions.info/tutorial.html This is the site of the RegexBuddy tool which I highly recommend. There's a cool tutorial in there, in which I learned most of what I know about regular expressions.
I find that a lot of people are using my Regular Expression Tester which allows the testing of Regular Expressions using the .NET RegEx classes.
For general information www.regular-expressions.info is good.
Try Regular-Expressions.info. They also sell tools but the tutorials are pretty good.
I've found Regular-Expressions.info to be most helpful. They also include examples for different languages.
Use a regular expression animator to see how they work. There are several different forms of notation for regular expressions, for instance SQL notation versus UNIX notation, so don't get hung up on the coding. Learn what is actually taking place when a match is made.
Here are a couple of possibilities