common

Common Regular Expressions

24th March 2008 - 2 minutes read time

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.


[A-Z][a-z][a-z] [0-9][0-9]*, [0-9]{4}

Will match a formatted date, such as Mar 24, 2007.

Time


([1-9]|1[0-2]):[0-5]\d(:[0-5]\d(\.\d{1,3})?)?

This will match HH:MM or HH:MM:SS or HH:MM:SS.mmm.

IP Address

Read the full article