Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 149825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:11:32+00:00 2026-05-11T09:11:32+00:00

I have an address class that uses a regular expression to parse the house

  • 0

I have an address class that uses a regular expression to parse the house number, street name, and street type from the first line of an address. This code is generally working well, but I’m posting here to share with the community and to see if anyone has suggestions for improvement.

Note: The STREETTYPES and QUADRANT constants contain all of the relevant street types and quadrants respectively.

I’ve included a subset here:

private const string STREETTYPES = @'ALLEY|ALY|ANNEX|AX|ARCADE|ARC|AVENUE|AV|AVE|BAYOU|BYU|BEACH|...';  private const string QUADRANTS = 'N|NORTH|S|SOUTH|E|EAST|W|WEST|NE|NORTHEAST|NW|NORTHWEST|SE|SOUTHEAST|SW|SOUTHWEST'; 

HouseNumber, Quadrant, StreetName, and StreetType are all properties on the class.

    private void Parse(string line1)     {         HouseNumber = string.Empty;         Quadrant = string.Empty;         StreetName = string.Empty;         StreetType = string.Empty;          if (!String.IsNullOrEmpty(line1))         {             string noPeriodsLine1 = String.Copy(line1);             noPeriodsLine1 = noPeriodsLine1.Replace('.', '');              string addressParseRegEx =                 @'(?ix)             ^             \s*             (?:                (?<housenumber>\d+)                (?:(?:\s+|-)(?<quadrant>' +                 QUADRANTS +                 @'))?                (?:(?:\s+|-)(?<streetname>\S+(?:\s+\S+)*?))??                (?:(?:\s+|-)(?<quadrant>' +                 QUADRANTS + @'))?                (?:(?:\s+|-)(?<streettype>' + STREETTYPES +                 @'))?                (?:(?:\s+|-)(?<streettypequalifier>(?!(?:' +                 QUADRANTS +                 @'))(?:\d+|\S+)))?                (?:(?:\s+|-)(?<streettypequadrant>(' +                 QUADRANTS + @')))??                (?:(?:\s+|-)(?<suffix>(?:ste|suite|po\sbox|apt)\s*\S*))?             |                (?:(?:po|postoffice|post\s+office)\s+box\s+(?<postofficebox>\S+))             )             \s*             $             ';             Match match = Regex.Match(noPeriodsLine1, addressParseRegEx);             if (match.Success)             {                 HouseNumber = match.Groups['housenumber'].Value;                 Quadrant = (string.IsNullOrEmpty(match.Groups['quadrant'].Value)) ? match.Groups['streettypequadrant'].Value : match.Groups['quadrant'].Value;                 if (match.Groups['streetname'].Captures.Count > 1)                 {                     foreach (Capture capture in match.Groups['streetname'].Captures)                     {                         StreetName += capture.Value + ' ';                     }                     StreetName = StreetName.Trim();                 }                 else                 {                     StreetName = (string.IsNullOrEmpty(match.Groups['streetname'].Value)) ? match.Groups['streettypequalifier'].Value : match.Groups['streetname'].Value;                 }                 StreetType = match.Groups['streettype'].Value;                  //if the matched street type is found                 //use the abbreviated version...especially for credit bureau calls                 string streetTypeAbbreviation;                 if (StreetTypes.TryGetValue(StreetType.ToUpper(), out streetTypeAbbreviation))                 {                     StreetType = streetTypeAbbreviation;                 }             }         }      } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T09:11:32+00:00Added an answer on May 11, 2026 at 9:11 am

    I don’t know what country you’re in, but if you’re in the USA and want to spend some money on address validation, you can buy related USPS products here. And here is a good place to find free word lists from the USPS for expected words and abbreviations. I’m sure similar pages are available for other countries.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class, ClassA that uses a client I wrote to send text
I have an object in a simple test scenario that uses EF Code First
In my application I have a Customer class and an Address class. The Customer
Problem: I have an address field from an Access database which has been converted
I have a form element that I want to address via javascript, but it
I have a linker command file that assigns the top address of the stack
I have a module that sends an email to a specified email address but
i have a java ee project which has a text file that uses a
If I have a class that contains only compile-time constants, for example, class A
Let's say I have a PHP Model-View-Controller framework that maps an address like http://example.com/admin/posts/edit/5

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.