Regular Expressions 101

Mailing Address (US Postal)

Open Workspace
  • PCRE (Legacy)
  • Match
0

Regular Expression

/
^(?:(?<numberstreet>\d+(?:\ +\w+)+(?=\n|\,))|(?<pobox>[P][.]?[O][.]?[\s|\-][B|b][O|o][X|x][\s]\d+(?=\n|\,)))?(?:\ *\,\ *)?(?<suite>(?:SUITE) [\#]?\d+)?(?:\ *\,\ *)?(?<citystatezip>(?<city>[^\,\s][\w\s]+)(?:\ *\,\ *)(?<stateabrv>[A-Z]{1,3})(?:\ +)(?<zipcode>\d{5}(?:\-\d*)?))?$
/
gmi

Description

Groups: street address (and suite if available), PO Box (if available), city, state (abbreviation) and zip code.

Submitted by Anonymous