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

  • Home
  • SEARCH
  • 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

Ask A Question

Stats

  • Questions 367k
  • Answers 367k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer A more general version of this question is asked at… May 14, 2026 at 5:01 pm
  • Editorial Team
    Editorial Team added an answer Assuming that the object represented by pat is a Class,… May 14, 2026 at 5:01 pm
  • Editorial Team
    Editorial Team added an answer I'm not sure if the HTC supports the viewport meta… May 14, 2026 at 5:01 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.