Do you have a list of common regular expressions that developers need?

By Alvin J. Alexander, devdaily.com

I've been asked several times, so I thought it might be helpful to post some of the most common regular expressions that are used in programming. Honestly I haven't tested any of these yet -- I did them off the top of my head -- but I think they will work for both Java and Perl developers.

Regular Expression What it Matches
^$ A blank line.
[A-Z][A-Z] Two character state abbreviation.
Note that you may choose to put spaces either before or after the regex.
.*, [A-Z][A-Z] City, State abbreviation.
[0-9]\{5\}(-[0-9]\{4\})? Zip Code.
Five digits, followed by an optional hyphen and four additional digits.
[0-9]\{3\}-[0-9]\{2\}-[0-9]\{4\} Social security number, such as:
###-##-####
\$[0-9]*.[0-9][0-9] Dollar amounts, specified with a leading $ symbol.
[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\} Date, in numeric format, such as 2003-08-06.
[A-Z][a-z][a-z] [0-9][0-9]*, [0-9]\{4\} Date, in format such as "Jan 3, 2003"


I'll add more regular expressions as I think of them, but these are some of the first that come to mind. I'm sure that other common regular expressions can easily be extrapolated from these.


devdaily logo