Useful Regular Expression Patterns

Phone Numbers:

  • simple match that allows dashes as separators:
  • allows periods, dashes or spaces as separators:
  • Matches to to the North American Numbering Plan (2009):

Postal Codes:

  • simple match:
    ^([A-Z]\d[A-Z])\ {0,1}(\d[A-Z]\d)$
  • allows unused “W” and “Z” as first characters:
  • 2009 rules:

U.S. Zip Codes:

  • Allows 5 and 5+4 zip codes:
    ^[0-9]{5}([- /]?[0-9]{4})?$

Roman Numerals:

  • Unlike the ones I found all over the internet, this one actually works (up to 3999):

Reading CSV:

  • honours quoted strings:
  • Also see this post

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s