Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Looking for Mailing Address RegEx

Last post 07-29-2010, 3:30 PM by emadeva. 2 replies.
Sort Posts: Previous Next
  •  07-29-2010, 11:21 AM 70218

    Looking for Mailing Address RegEx

    Hi Everyone,

     I would like to know if you could show me 3 different RegEx strings so I can extract the following:

    RegEx1 to extract the house number and street name of a mailing address excluding any apartment number or letter.
    RegEx2 to extract the Apartment number or letter from a mailing address
    RegEx3 to extract the City, State and zip

    Sample Data:

    123 Testing Ave Apt 202
    334 Another St Oceanside NY
    883 Some Other Drive Apt 3B Ann Arbor, MI
    333 Gorham Rd Unit 3 Lowell, MA 01852

    Thanks.

    Truly,
    Emad

    Filed under:
  •  07-29-2010, 1:03 PM 70219 in reply to 70218

    Re: Looking for Mailing Address RegEx

    This is actually a lot more complicated than you may think.  There are just too many variations in City and street names to allow you to come up any totally reliable.  In the posting guidelines we ask that you do not make up sample data, although this type of question is an understandable exception, because people tend to make up examples that are the simplest case lending to suggestions that fail when the real data turns out to be more complex.   My suggestion for  some like this is to use actual address of public building in your (or other town), like city hall or the post office.  Another reason we ask people not to make up sample is they don't show the context of the source data.  http://regexadvice.com/blogs/mash/archive/2007/10/01/Remember-where-you-come-from.aspx

     

    You also fail to mention which programming language/Application you were doing this in. Here is a single pattern that does all of the above but it's not perfect as stated for reasons above and it's written only for .Net. http://www.regexlib.com/REDetails.aspx?regexp_id=472 


    Michael

    "In theory, theory and practice are the same. In practice, they are not."
    Albert Einstein
  •  07-29-2010, 3:30 PM 70240 in reply to 70219

    Re: Looking for Mailing Address RegEx

    Hi Mash,

    Thanks for the reply.

    It's for VB.NET and we would be happy if we could separate the street address from the apartment portion of the string.

    Would it also be difficult to also extract the city, state and zip as well?

    We plan to load it up with a statement like:
    mcMyMatches = myRegEx.Matches(pStringToParse)

    and use a For Each loop to get the portions we need.

    By the way, I see your location is Birmingham. I lived in Huntsville for about 2 years when doing an Oracle contract there.

    Truly,
    Emad

View as RSS news feed in XML