Regular Expressions

I just love Regular Expressions. I first came in to contact with them many years ago while doing Perl development. Anyone having to pull data out of text documents or textual input fields must become familiar with Regex as the alternatives of linear token parsing or token searching pale in comparison to the intelligent parsing capability of a regular expression.

PCRE has become a cross-platform/cross-language standard for Regular Expressions supported in whole or part in Perl, PHP, Python, Ruby, C#, Javascript, and Actionscript.


Phone Number

Parses a 10-digit phone number optionally followed by an extension.

Expanded and documented:

These values will all be parsed successfully. Group captures are marked in red (1), green (2),  blue (3), and orange (4):

  • 9999999999
  • 1-9999999999
  • (999) 9999999
  • 1(999) 9999999 ext 9999
  • (999) 9999999 x 9999
  • 99999999999999
  • 1-9999999999+9999

City, State, Zip Code

Parses City, State, and Zip Code.

Expanded and documented:

These values will all be parsed successfully. Group captures are marked in red (1), green (2),  blue (3), and orange (4):

  • Los Angeles, CA 90037
  • Fort Atkinson, WI 53538-0901 USA
  • New York NY 10001

About sthames42

A truly brilliant software engineer of great wit and humility. Once young and fit, a great colleague, and serious danger to the ladies. Now old, fat, and married fortunately, but still sharp as a marble.

Leave a Reply

Your email address will not be published. Required fields are marked *