I hope the descriptions of how they function are of use in deciphering the details of each of these two expressions.
Please feel free to add a comment with your favorite expressions for matching an email or Web address.
The expression logically breaks address matches into four groups. It’s good to note that this expression is not case-sensitive and will match email addresses written in mixed case.
You don’t explicitly need to tell your regular expression engine to ignore case.
These expressions are definitely very useful and come up time and time again in the tasks of any developer.
Since I’m mentioning the site, I definitely suggest browsing over to it if you are looking for further reading about regular expressions including sample code and reference material.
Also, have a look at a free online regular expression tool by Derek Slager. $ For starters, you’ll want to make sure that you set your expression to ignore the case, or capital letters in a URL will cause it to fail.
You can use this tool to test your regular expressions if you don’t have a program on your computer to do so. Alternately, convert the URL to lower case before applying this expression.
I have spent quite some time trying to find a good online regular expression testing tool, but every one I have found is either too expensive, or full of advertising, so this tool is definitely worth checking out. To review the structure of the expression; the ^ symbol matches the start of the line and the $ symbol matches the end of the line.
In this article I’ll cover two useful regular expressions that often come in handy when writing validation logic for a Web page.
Most programmers will find they need to either validate a URL or an Email at some point, and the example expressions below are the most commonly used versions of each expression.
I’m not sure who originally created each of these expressions, so I have no idea who I can give the credit for these to, but they have helped me often.
Bottom line for these two examples is that I like to use the example expressions found in an article on Net Tuts+/and modify them to meet my needs.