Skip to content

Addresses

Address blocks and one-line addresses: recipient, street or post office box with building, suite or mail stop, city, state, postal code and country.

input.txtHover a value to see its type · click it to find it in the treeRun in Studio
Advanced Systems Center (ASC)
12201 Sunrise Valley Drive
Reston, VA 20192
United States

National Geospatial Technical Operations Center — Denver
810 Eighth Street
Lakewood, CO 80225-0046
United States

National Geospatial Technical Operations Center — Rolla
1400 Independence Road
Rolla, MO 65401
United States

USGS Denver Library
Box 25046, MS 914
Denver Federal Center
Denver, CO 80225-0046
United States
addresses.ymlspec
# Postal addresses of the United States and Canada.
#
# Values: StreetAddress (a numbered street, a numbered route or a post office box) and Locality
# (city, state or province and postal code). Fact: Address, which composes them with the recipient
# name, unit designators (suite, room, building, floor, mail stop), the named facility after the street
# line and the country, in a block of lines or on one line.

StreetAddress:
  $local:
    HouseNumber: '\d+[A-Z]?(-\d+[A-Z]?)?'

    Direction:
      - '[NS][EW]'
      - 'N\.[EW]\.'
      - 'S\.[EW]\.'
      - '[NSEW]\.?'
      - '(North|South)(east|west)?'
      - 'East'
      - 'West'

  $fields: { number: HouseNumber }

  Street:
    $local:
      Suffix:
        $flags: [ CASE_INSENSITIVE ]
        $patterns:
          - 'Street'
          - 'St'
          - 'Avenue'
          - 'Ave'
          - 'Road'
          - 'Rd'
          - 'Drive'
          - 'Dr'
          - 'Boulevard'
          - 'Blvd'
          - 'Lane'
          - 'Ln'
          - 'Way'
          - 'Court'
          - 'Ct'
          - 'Place'
          - 'Pl'
          - 'Parkway'
          - 'Pkwy'
          - 'Circle'
          - 'Cir'
          - 'Terrace'
          - 'Trail'
          - 'Pike'
          - 'Plaza'
          - 'Square'
          - 'Loop'
          - 'Crescent'
          - 'Expressway'
          - 'Turnpike'

      StreetName: '([\p{Lu}\d][\p{L}\d''.-]* )+${Suffix}\.?(,? ${Direction})?'

    $fields: { name: StreetName }
    $patterns: '#{number} #{name}'

  Route:
    $local:
      RouteName: '((U\.?S\.?|State|County|Interstate|Farm to Market|Ranch Road) )?(Highway|Hwy\.?|Route|Rte\.?|Road) \d+[A-Z]?( ${Direction})?'

    $fields: { name: RouteName }
    $patterns: '#{number} #{name}'

  PostBox:
    $local:
      BoxNumber: '\d+'

    $fields: { number: BoxNumber }
    $patterns:
      - '(P\.? ?O\.? ?|Post Office )?(Box|BOX) #{number}'
      - 'POB #{number}'

Locality:
  $local:
    City: '\p{Lu}[\p{L}''.-]*( (\p{Lu}[\p{L}''.-]*|de|du|des|la|le|d''\p{Lu}\p{L}*))*'

    PostalCode:
      Zip: '\d{5}([-–]\d{4})?'
      Canadian: '[A-Z]\d[A-Z] ?\d[A-Z]\d'

    State:
      Alabama: { $patterns: [ 'AL', 'Alabama' ], $value: 'AL' }
      Alaska: { $patterns: [ 'AK', 'Alaska' ], $value: 'AK' }
      Arizona: { $patterns: [ 'AZ', 'Arizona' ], $value: 'AZ' }
      Arkansas: { $patterns: [ 'AR', 'Arkansas' ], $value: 'AR' }
      California: { $patterns: [ 'CA', 'California' ], $value: 'CA' }
      Colorado: { $patterns: [ 'CO', 'Colorado' ], $value: 'CO' }
      Connecticut: { $patterns: [ 'CT', 'Connecticut' ], $value: 'CT' }
      Delaware: { $patterns: [ 'DE', 'Delaware' ], $value: 'DE' }
      DistrictOfColumbia: { $patterns: [ 'DC', 'D\.C', 'District of Columbia' ], $value: 'DC' }
      Florida: { $patterns: [ 'FL', 'Florida' ], $value: 'FL' }
      Georgia: { $patterns: [ 'GA', 'Georgia' ], $value: 'GA' }
      Hawaii: { $patterns: [ 'HI', 'Hawaii' ], $value: 'HI' }
      Idaho: { $patterns: [ 'ID', 'Idaho' ], $value: 'ID' }
      Illinois: { $patterns: [ 'IL', 'Illinois' ], $value: 'IL' }
      Indiana: { $patterns: [ 'IN', 'Indiana' ], $value: 'IN' }
      Iowa: { $patterns: [ 'IA', 'Iowa' ], $value: 'IA' }
      Kansas: { $patterns: [ 'KS', 'Kansas' ], $value: 'KS' }
      Kentucky: { $patterns: [ 'KY', 'Kentucky' ], $value: 'KY' }
      Louisiana: { $patterns: [ 'LA', 'Louisiana' ], $value: 'LA' }
      Maine: { $patterns: [ 'ME', 'Maine' ], $value: 'ME' }
      Maryland: { $patterns: [ 'MD', 'Maryland' ], $value: 'MD' }
      Massachusetts: { $patterns: [ 'MA', 'Massachusetts' ], $value: 'MA' }
      Michigan: { $patterns: [ 'MI', 'Michigan' ], $value: 'MI' }
      Minnesota: { $patterns: [ 'MN', 'Minnesota' ], $value: 'MN' }
      Mississippi: { $patterns: [ 'MS', 'Mississippi' ], $value: 'MS' }
      Missouri: { $patterns: [ 'MO', 'Missouri' ], $value: 'MO' }
      Montana: { $patterns: [ 'MT', 'Montana' ], $value: 'MT' }
      Nebraska: { $patterns: [ 'NE', 'Nebraska' ], $value: 'NE' }
      Nevada: { $patterns: [ 'NV', 'Nevada' ], $value: 'NV' }
      NewHampshire: { $patterns: [ 'NH', 'New Hampshire' ], $value: 'NH' }
      NewJersey: { $patterns: [ 'NJ', 'New Jersey' ], $value: 'NJ' }
      NewMexico: { $patterns: [ 'NM', 'New Mexico' ], $value: 'NM' }
      NewYork: { $patterns: [ 'NY', 'New York' ], $value: 'NY' }
      NorthCarolina: { $patterns: [ 'NC', 'North Carolina' ], $value: 'NC' }
      NorthDakota: { $patterns: [ 'ND', 'North Dakota' ], $value: 'ND' }
      Ohio: { $patterns: [ 'OH', 'Ohio' ], $value: 'OH' }
      Oklahoma: { $patterns: [ 'OK', 'Oklahoma' ], $value: 'OK' }
      Oregon: { $patterns: [ 'OR', 'Oregon' ], $value: 'OR' }
      Pennsylvania: { $patterns: [ 'PA', 'Pennsylvania' ], $value: 'PA' }
      RhodeIsland: { $patterns: [ 'RI', 'Rhode Island' ], $value: 'RI' }
      SouthCarolina: { $patterns: [ 'SC', 'South Carolina' ], $value: 'SC' }
      SouthDakota: { $patterns: [ 'SD', 'South Dakota' ], $value: 'SD' }
      Tennessee: { $patterns: [ 'TN', 'Tennessee' ], $value: 'TN' }
      Texas: { $patterns: [ 'TX', 'Texas' ], $value: 'TX' }
      Utah: { $patterns: [ 'UT', 'Utah' ], $value: 'UT' }
      Vermont: { $patterns: [ 'VT', 'Vermont' ], $value: 'VT' }
      Virginia: { $patterns: [ 'VA', 'Virginia' ], $value: 'VA' }
      Washington: { $patterns: [ 'WA', 'Washington' ], $value: 'WA' }
      WestVirginia: { $patterns: [ 'WV', 'West Virginia' ], $value: 'WV' }
      Wisconsin: { $patterns: [ 'WI', 'Wisconsin' ], $value: 'WI' }
      Wyoming: { $patterns: [ 'WY', 'Wyoming' ], $value: 'WY' }
      AmericanSamoa: { $patterns: [ 'AS', 'American Samoa' ], $value: 'AS' }
      Guam: { $patterns: [ 'GU', 'Guam' ], $value: 'GU' }
      NorthernMarianaIslands: { $patterns: [ 'MP', 'Northern Mariana Islands' ], $value: 'MP' }
      PuertoRico: { $patterns: [ 'PR', 'Puerto Rico' ], $value: 'PR' }
      VirginIslands: { $patterns: [ 'VI', '(U\.S\. )?Virgin Islands' ], $value: 'VI' }
      Alberta: { $patterns: [ 'AB', 'Alberta' ], $value: 'AB' }
      BritishColumbia: { $patterns: [ 'BC', 'British Columbia' ], $value: 'BC' }
      Manitoba: { $patterns: [ 'MB', 'Manitoba' ], $value: 'MB' }
      NewBrunswick: { $patterns: [ 'NB', 'New Brunswick' ], $value: 'NB' }
      NewfoundlandAndLabrador: { $patterns: [ 'NL', 'Newfoundland and Labrador', 'Newfoundland' ], $value: 'NL' }
      NovaScotia: { $patterns: [ 'NS', 'Nova Scotia' ], $value: 'NS' }
      NorthwestTerritories: { $patterns: [ 'NT', 'Northwest Territories' ], $value: 'NT' }
      Nunavut: { $patterns: [ 'NU', 'Nunavut' ], $value: 'NU' }
      Ontario: { $patterns: [ 'ON', 'Ontario' ], $value: 'ON' }
      PrinceEdwardIsland: { $patterns: [ 'PE', 'Prince Edward Island' ], $value: 'PE' }
      Quebec: { $patterns: [ 'QC', 'Quebec', 'Québec' ], $value: 'QC' }
      Saskatchewan: { $patterns: [ 'SK', 'Saskatchewan' ], $value: 'SK' }
      Yukon: { $patterns: [ 'YT', 'Yukon' ], $value: 'YT' }

  $fields: { city: City, state: State, postalCode: PostalCode }
  $patterns:
    - '#{city},? #{state}\.?,? +#{postalCode}'
    - '#{city} \(#{state}\) +#{postalCode}'

Unit:
  MailStop: '(MS|M/S|Mail ?[Ss]top|Mail [Cc]ode|MC)\.? ?#?[A-Z]?\d+[A-Z\d-]*'
  Suite: '(Suite|Ste\.?|STE) #?[A-Z\d][A-Z\d-]*'
  Room: '(Room|Rm\.?) #?[A-Z\d][A-Z\d-]*'
  Building: '(Building|Bldg\.?) #?[A-Z\d][A-Z\d-]*'
  Floor:
    - '\d+(st|nd|rd|th) (Floor|Fl\.?)'
    - '(Floor|Fl\.?) \d+'
  Apartment: '(Apartment|Apt\.?|Unit) #?[A-Z\d][A-Z\d-]*'

Address:
  $local:
    Separator: '(,? *\n *|, )'

    Label:
      $flags: [ CASE_INSENSITIVE ]
      $patterns: '((Mailing|Postal|Street|Physical|Shipping|Delivery|Office|Our) )?Address'

    NameLine: '[\p{L}\d(][\p{L}\d ().&''’—–-]*[\p{L}\d)]'

    Facility: '(\p{Lu}[\p{L}''.&-]* )+(Center|Centre|Building|Plaza|Complex|Campus|Tower|Park|Hall|Annex|Station|Laboratory|Arsenal|Courthouse)'

    Country:
      UnitedStates:
        $patterns:
          - 'United States( of America)?'
          - 'U\.S\.A\.?'
          - 'USA'
          - 'U\.S\.'
          - 'US'
        $value: 'United States'

      Canada: { $patterns: [ 'Canada', 'CANADA' ], $value: 'Canada' }

  $fields:
    name: 'NameLine[]'
    street: StreetAddress
    units: 'Unit[]'
    facility: Facility
    locality: Locality
    country: Country

  $patterns: '(${Label}:? *\n? *)?(#{name}${Separator})*(#{units}${Separator})*#{street}((${Separator}| )(#{units}|#{facility}))*${Separator}#{locality}((${Separator}| )#{country})?'
$ texomy parse input.txt -m addresses
addresses.json
[
  {
    "type": "Address",
    "start": 0,
    "end": 87,
    "fields": {
      "name": [
        {
          "type": "NameLine",
          "start": 0,
          "end": 29,
          "text": "Advanced Systems Center (ASC)"
        }
      ],
      "street": {
        "type": "StreetAddress::Street",
        "start": 30,
        "end": 56,
        "fields": {
          "number": {
            "type": "HouseNumber",
            "start": 30,
            "end": 35,
            "text": "12201"
          },
          "name": {
            "type": "StreetName",
            "start": 36,
            "end": 56,
            "text": "Sunrise Valley Drive"
          }
        }
      },
      "locality": {
        "type": "Locality",
        "start": 57,
        "end": 73,
        "fields": {
          "city": {
            "type": "City",
            "start": 57,
            "end": 63,
            "text": "Reston"
          },
          "state": {
            "type": "State::Virginia",
            "start": 65,
            "end": 67,
            "text": "VA",
            "value": "VA"
          },
          "postalCode": {
            "type": "PostalCode::Zip",
            "start": 68,
            "end": 73,
            "text": "20192"
          }
        }
      },
      "country": {
        "type": "Country::UnitedStates",
        "start": 74,
        "end": 87,
        "text": "United States",
        "value": "United States"
      }
    }
  },
  {
    "type": "Address",
    "start": 89,
    "end": 201,
    "fields": {
      "name": [
        {
          "type": "NameLine",
          "start": 89,
          "end": 145,
          "text": "National Geospatial Technical Operations Center — Denver"
        }
      ],
      "street": {
        "type": "StreetAddress::Street",
        "start": 146,
        "end": 163,
        "fields": {
          "number": {
            "type": "HouseNumber",
            "start": 146,
            "end": 149,
            "text": "810"
          },
          "name": {
            "type": "StreetName",
            "start": 150,
            "end": 163,
            "text": "Eighth Street"
          }
        }
      },
      "locality": {
        "type": "Locality",
        "start": 164,
        "end": 187,
        "fields": {
          "city": {
            "type": "City",
            "start": 164,
            "end": 172,
            "text": "Lakewood"
          },
          "state": {
            "type": "State::Colorado",
            "start": 174,
            "end": 176,
            "text": "CO",
            "value": "CO"
          },
          "postalCode": {
            "type": "PostalCode::Zip",
            "start": 177,
            "end": 187,
            "text": "80225-0046"
          }
        }
      },
      "country": {
        "type": "Country::UnitedStates",
        "start": 188,
        "end": 201,
        "text": "United States",
        "value": "United States"
      }
    }
  },
  {
    "type": "Address",
    "start": 203,
    "end": 311,
    "fields": {
      "name": [
        {
          "type": "NameLine",
          "start": 203,
          "end": 258,
          "text": "National Geospatial Technical Operations Center — Rolla"
        }
      ],
      "street": {
        "type": "StreetAddress::Street",
        "start": 259,
        "end": 281,
        "fields": {
          "number": {
            "type": "HouseNumber",
            "start": 259,
            "end": 263,
            "text": "1400"
          },
          "name": {
            "type": "StreetName",
            "start": 264,
            "end": 281,
            "text": "Independence Road"
          }
        }
      },
      "locality": {
        "type": "Locality",
        "start": 282,
        "end": 297,
        "fields": {
          "city": {
            "type": "City",
            "start": 282,
            "end": 287,
            "text": "Rolla"
          },
          "state": {
            "type": "State::Missouri",
            "start": 289,
            "end": 291,
            "text": "MO",
            "value": "MO"
          },
          "postalCode": {
            "type": "PostalCode::Zip",
            "start": 292,
            "end": 297,
            "text": "65401"
          }
        }
      },
      "country": {
        "type": "Country::UnitedStates",
        "start": 298,
        "end": 311,
        "text": "United States",
        "value": "United States"
      }
    }
  },
  {
    "type": "Address",
    "start": 313,
    "end": 408,
    "fields": {
      "name": [
        {
          "type": "NameLine",
          "start": 313,
          "end": 332,
          "text": "USGS Denver Library"
        }
      ],
      "street": {
        "type": "StreetAddress::PostBox",
        "start": 333,
        "end": 342,
        "fields": {
          "number": {
            "type": "BoxNumber",
            "start": 337,
            "end": 342,
            "text": "25046"
          }
        }
      },
      "units": [
        {
          "type": "Unit::MailStop",
          "start": 344,
          "end": 350,
          "text": "MS 914"
        }
      ],
      "facility": {
        "type": "Facility",
        "start": 351,
        "end": 372,
        "text": "Denver Federal Center"
      },
      "locality": {
        "type": "Locality",
        "start": 373,
        "end": 394,
        "fields": {
          "city": {
            "type": "City",
            "start": 373,
            "end": 379,
            "text": "Denver"
          },
          "state": {
            "type": "State::Colorado",
            "start": 381,
            "end": 383,
            "text": "CO",
            "value": "CO"
          },
          "postalCode": {
            "type": "PostalCode::Zip",
            "start": 384,
            "end": 394,
            "text": "80225-0046"
          }
        }
      },
      "country": {
        "type": "Country::UnitedStates",
        "start": 395,
        "end": 408,
        "text": "United States",
        "value": "United States"
      }
    }
  }
]

About this spec

Postal addresses of the United States and Canada, as blocks or on one line: the recipient name, the street address or post office box with any building, suite or mail stop, the city, the state or province, the postal code and the country.

Package files

  • addresses.yml
  • samples/blocks.txt
  • samples/inline.txt
  • tests/addresses.test.yml
  • tests/expected/blocks.yaml
  • tests/expected/inline.yaml
  • tests/expected/sample.yaml
  • texomy.json

41 nodes from 4 top-level matches.

Run it yourself

Save the example from Studio to a folder, then in that folder:

texomy parse input.txt -m addresses
texomy test

Write the spec once. Run it on everything.

Install the CLI, connect your agent, and turn your first sample into typed data in minutes.

brew install texomy/tap/texomy