Regular Expressions

Useful regular expressions

Regular Expression To Find Single Apersands In Text

Encoding special characters in a block of HTML or other code can be a pain because there might already be ampersands there that impart encoding. This might be an ampersand that has already been encoded with a &, or it might be an ampersand in the code as an if statement or similar.

Use the following regular expression to find any ampersand that hasn't already been encoded.

philipnorton42 Mon, 09/22/2008 - 09:24
Common Regular Expressions

Here are some of the regular expressions that I frequently use.

Find a blank line

^$

Spaces

[ \t]+

You can use this to break a text string apart into words.

Date

\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}

This will match anything in the format mm/dd/yyyy, or even dd/mm/yyyy.

philipnorton42 Mon, 03/24/2008 - 09:32
RegExLib.com: The Regular Expression Library

Writing regular expressions can sometimes be a real pain, especially if you are not used to them. Rather than trying for yourself to make a regular expression you might want to think about looking for regular expressions that other people have made. Rather than reinventing the wheel to prove you can do something,using free third party regular expressions can save you a lot of time.

philipnorton42 Sat, 03/22/2008 - 22:51
reWork: A Regular Expression Workbench

Regular expressions are a very useful tool for any programmer wanting to validate input, format strings, change words, reformat data or even split apart a string into an array. However, when you are starting out, writing them it can be hard going, they are not very easy to learn and the only way to really understand them is to practice, practice, practice.

philipnorton42 Fri, 03/21/2008 - 16:11