<p>Problem: I have an address field from an Access database which has been converted to SQL Server 2005. This field has everything all in one field. I need to parse out the address's individual sections into their appropriate fields in a normalized table. I need to do this for approximately 4,000 records, and it needs to be repeatable.</p>
<p>Assumptions:</p>
<ol>
<li><p>Assume an address in the US (for now)</p>
</li>
<li><p>assume that the input string will sometimes contain an addressee (the person being addressed) and/or a second street address (i.e. Suite B)</p>
</li>
<li><p>states may be abbreviated</p>
</li>
<li><p>zip code could be standard 5 digits or zip+4</p>
</li>
<li><p>there are typos in some instances</p>
</li>
</ol>
<p>UPDATE: In response to the questions posed, standards were not universally followed; I need need to store the individual values, not just geocode and errors means typo (corrected above)</p>
<p>Sample Data:</p>
<ul>
<li><p>A. P. Croll &amp; Son  2299 Lewes-Georgetown Hwy, Georgetown, DE 19947</p>
</li>
<li><p>11522 Shawnee Road, Greenwood DE  19950</p>
</li>
<li><p>144 Kings Highway, S.W. Dover, DE  19901</p>
</li>
<li><p>Intergrated Const. Services 2 Penns Way Suite 405 New Castle, DE  19720</p>
</li>
<li><p>Humes Realty 33 Bridle Ridge Court, Lewes, DE  19958</p>
</li>
<li><p>Nichols Excavation 2742 Pulaski Hwy Newark, DE  19711</p>
</li>
<li><p>2284 Bryn Zion Road, Smyrna, DE  19904</p>
</li>
<li><p>VEI Dover Crossroads, LLC  1500 Serpentine Road, Suite 100 Baltimore MD  21</p>
</li>
<li><p>580 North Dupont Highway Dover, DE  19901</p>
</li>
<li><p>P.O. Box 778 Dover, DE  19903</p>
</li>
</ul>

[{'answer_id': 16422, 'author': 'pix0r', 'author_id': 72, 'author_profile': 'https://Stackoverflow.com/users/72', 'pm_score': 2, 'selected': False, 'text': "<p>This won't solve your problem, but if you only needed lat/long data for these addresses, the Google Maps API will parse non-formatted addresses pretty well.</p>\n"}, {'answer_id': 16423, 'author': 'Yaakov Ellis', 'author_id': 51, 'author_profile': 'https://Stackoverflow.com/users/51', 'pm_score': 3, 'selected': False, 'text': '<p>Are there any standards at all in the way that the addresses are recorded? For example: </p>\n\n<ol>\n<li>Are there always commas or new-lines separating street1 from street2 from city from state from zip? </li>\n<li>Are address types (road, street, boulevard, etc) always spelled out? always abbreviated? Some of each? </li>\n<li>Define "error". </li>\n</ol>\n\n<p>My general answer is a series of Regular Expressions, though the complexity of this depends on the answer. And if there is no consistency at all, then you may only be able to achieve partial success with a Regex (ie: filtering out zip code and state) and will have to do the rest by hand (or at least go through the rest very carefully to make sure you spot the errors).</p>\n'}, {'answer_id': 16444, 'author': 'Tim Sullivan', 'author_id': 722, 'author_profile': 'https://Stackoverflow.com/users/722', 'pm_score': 8, 'selected': True, 'text': '<p>I\'ve done a lot of work on this kind of parsing. Because there are errors you won\'t get 100% accuracy, but there are a few things you can do to get most of the way there, and then do a visual BS test. Here\'s the general way to go about it. It\'s not code, because it\'s pretty academic to write it, there\'s no weirdness, just lots of string handling.</p>\n\n<p>(Now that you\'ve posted some sample data, I\'ve made some minor changes)</p>\n\n<ol>\n<li>Work backward. Start from the zip code, which will be near the end, and in one of two known formats: XXXXX or XXXXX-XXXX. If this doesn\'t appear, you can assume you\'re in the city, state portion, below.</li>\n<li>The next thing, before the zip, is going to be the state, and it\'ll be either in a two-letter format, or as words. You know what these will be, too -- there\'s only 50 of them. Also, you could soundex the words to help compensate for spelling errors.</li>\n<li>before that is the city, and it\'s <em>probably</em> on the same line as the state. You could use a <a href="http://zipinfo.com" rel="noreferrer">zip-code database</a> to check the city and state based on the zip, or at least use it as a BS detector.</li>\n<li>The street address will generally be one or two lines. The second line will generally be the suite number if there is one, but it could also be a PO box.</li>\n<li>It\'s going to be near-impossible to detect a name on the first or second line, though if it\'s not prefixed with a number (or if it\'s prefixed with an "attn:" or "attention to:" it could give you a hint as to whether it\'s a name or an address line.</li>\n</ol>\n\n<p>I hope this helps somewhat.</p>\n'}, {'answer_id': 16446, 'author': 'AdamSane', 'author_id': 805, 'author_profile': 'https://Stackoverflow.com/users/805', 'pm_score': 1, 'selected': False, 'text': '<p>There are data services that given a zip code will give you list of street names in that zip code.</p>\n\n<p>Use a regex to extract Zip or City State - find the correct one or if a error get both.\npull the list of streets from a <a href="http://www.melissadata.com/lookups/zipstreet.asp" rel="nofollow noreferrer">data source</a> Correct the city and state, and then street address. Once you get a valid Address line 1, city, state, and zip you can then make assumptions on address line 2..3</p>\n'}, {'answer_id': 16454, 'author': 'Jay Mooney', 'author_id': 733, 'author_profile': 'https://Stackoverflow.com/users/733', 'pm_score': 3, 'selected': False, 'text': "<p>Based on the sample data:</p>\n\n<ol>\n<li><p>I would start at the end of the string.  Parse a Zip-code (either format).  Read end to first space. If no Zip Code was found Error.</p></li>\n<li><p>Trim the end then for spaces and special chars (commas)</p></li>\n<li><p>Then move on to State, again use the Space as the delimiter.  Maybe use a lookup list to validate 2 letter state codes, and full state names.  If no valid state found, error.</p></li>\n<li><p>Trim spaces and commas from the end again.</p></li>\n<li><p>City gets tricky, I would actually use a comma here, at the risk of getting too much data in the city.  Look for the comma, or beginning of the line.</p></li>\n<li><p>If you still have chars left in the string, shove all of that into an address field.</p></li>\n</ol>\n\n<p>This isn't perfect, but it should be a pretty good starting point.</p>\n"}, {'answer_id': 16472, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<p>Another request for sample data.</p>\n\n<p>As has been mentioned I would work backwards from the zip.</p>\n\n<p>Once you have a zip I would query a zip database, store the results, and remove them &amp; the zip from the string. </p>\n\n<p>That will leave you with the address mess. MOST (All?) addresses will start with a number so  find the first occurrence of a number in the remaining string and grab everything from it to the (new) end of the string. That will be your address. Anything to the left of that number is likely an addressee.</p>\n\n<p>You should now have the City, State, &amp; Zip stored in a table and possibly two strings, addressee and address. For the address, check for the existence of "Suite" or "Apt." etc. and split that into two values (address lines 1 &amp; 2). </p>\n\n<p>For the addressee I would punt and grab the last word of that string as the last name and put the rest into the first name field. If you don\'t want to do that, you\'ll need to check for salutation (Mr., Ms., Dr., etc.) at the start and make some assumptions based on the number of spaces as to how the name is made up. </p>\n\n<p>I don\'t think there\'s any way you can parse with 100% accuracy.</p>\n'}, {'answer_id': 16475, 'author': 'Christopher Mahan', 'author_id': 479, 'author_profile': 'https://Stackoverflow.com/users/479', 'pm_score': 4, 'selected': False, 'text': '<p>I\'ve done this in the past.</p>\n\n<p>Either do it manually, (build a nice gui that helps the user do it quickly) or have it automated and check against a recent address database (you have to buy that) and manually handle errors. </p>\n\n<p>Manual handling will take about 10 seconds each, meaning you can do 3600/10 = 360 per hour, so 4000 should take you approximately 11-12 hours. This will give you a high rate of accuracy.</p>\n\n<p>For automation, you <em>need</em> a recent US address database, and tweak your rules against that.  I suggest not going fancy on the regex (hard to maintain long-term, so many exceptions). Go for 90% match against the database, do the rest manually.</p>\n\n<p>Do get a copy of Postal Addressing Standards (USPS) at <a href="http://pe.usps.gov/cpim/ftp/pubs/Pub28/pub28.pdf" rel="noreferrer">http://pe.usps.gov/cpim/ftp/pubs/Pub28/pub28.pdf</a> and notice it is 130+ pages long. Regexes to implement that would be nuts.</p>\n\n<p>For international addresses, all bets are off. US-based workers would not be able to validate. </p>\n\n<p>Alternatively, use a data service. I have, however, no recommendations.</p>\n\n<p>Furthermore: when you do send out the stuff in the mail (that\'s what it\'s for, right?) make sure you put "address correction requested" on the envelope (in the right place) and <em>update</em> the database. (We made a simple gui for the front desk person to do that; the person who actually sorts through the mail)</p>\n\n<p>Finally, when you have scrubbed data, look for duplicates.</p>\n'}, {'answer_id': 16527, 'author': 'engtech', 'author_id': 175, 'author_profile': 'https://Stackoverflow.com/users/175', 'pm_score': 2, 'selected': False, 'text': "<p>If it's human entered data, then you'll spend too much time trying to code around the exceptions.</p>\n\n<p>Try:</p>\n\n<ol>\n<li><p>Regular expression to extract the zip code</p></li>\n<li><p>Zip code lookup (via appropriate government DB) to get the correct address</p></li>\n<li><p>Get an intern to manually verify the new data matches the old</p></li>\n</ol>\n"}, {'answer_id': 16531, 'author': 'Kevin', 'author_id': 40, 'author_profile': 'https://Stackoverflow.com/users/40', 'pm_score': 3, 'selected': False, 'text': "<blockquote>\n  <p>This won't solve your problem, but if\n  you only needed lat/long data for\n  these addresses, the Google Maps API\n  will parse non-formatted addresses\n  pretty well.</p>\n</blockquote>\n\n<p>Good suggestion, alternatively you can execute a CURL request for each address to Google Maps and it will return the properly formatted address.  From that, you can regex to your heart's content.</p>\n"}, {'answer_id': 16561, 'author': 'Nicholas Trandem', 'author_id': 765, 'author_profile': 'https://Stackoverflow.com/users/765', 'pm_score': 4, 'selected': False, 'text': "<p>I've been working in the address processing domain for about 5 years now, and there really is no silver bullet. The correct solution is going to depend on the value of the data. If it's not very valuable, throw it through a parser as the other answers suggest. If it's even somewhat valuable you'll definitely need to have a human evaluate/correct all the results of the parser. If you're looking for a fully automated, repeatable solution, you probably want to talk to a address correction vendor like Group1 or Trillium.</p>\n"}, {'answer_id': 16819, 'author': 'Rob Allen', 'author_id': 149, 'author_profile': 'https://Stackoverflow.com/users/149', 'pm_score': 4, 'selected': False, 'text': '<p>After the advice here, I have devised the following function in VB which creates passable, although not always perfect (if a company name and a suite line are given, it combines the suite and city) usable data. Please feel free to comment/refactor/yell at me for breaking one of my own rules, etc.: </p>\n\n<pre class="lang-vb prettyprint-override"><code>Public Function parseAddress(ByVal input As String) As Collection\n    input = input.Replace(",", "")\n    input = input.Replace("  ", " ")\n    Dim splitString() As String = Split(input)\n    Dim streetMarker() As String = New String() {"street", "st", "st.", "avenue", "ave", "ave.", "blvd", "blvd.", "highway", "hwy", "hwy.", "box", "road", "rd", "rd.", "lane", "ln", "ln.", "circle", "circ", "circ.", "court", "ct", "ct."}\n    Dim address1 As String\n    Dim address2 As String = ""\n    Dim city As String\n    Dim state As String\n    Dim zip As String\n    Dim streetMarkerIndex As Integer\n\n    zip = splitString(splitString.Length - 1).ToString()\n    state = splitString(splitString.Length - 2).ToString()\n    streetMarkerIndex = getLastIndexOf(splitString, streetMarker) + 1\n    Dim sb As New StringBuilder\n\n    For counter As Integer = streetMarkerIndex To splitString.Length - 3\n        sb.Append(splitString(counter) + " ")\n    Next counter\n    city = RTrim(sb.ToString())\n    Dim addressIndex As Integer = 0\n\n    For counter As Integer = 0 To streetMarkerIndex\n        If IsNumeric(splitString(counter)) _\n            Or splitString(counter).ToString.ToLower = "po" _\n            Or splitString(counter).ToString().ToLower().Replace(".", "") = "po" Then\n                addressIndex = counter\n            Exit For\n        End If\n    Next counter\n\n    sb = New StringBuilder\n    For counter As Integer = addressIndex To streetMarkerIndex - 1\n        sb.Append(splitString(counter) + " ")\n    Next counter\n\n    address1 = RTrim(sb.ToString())\n\n    sb = New StringBuilder\n\n    If addressIndex = 0 Then\n        If splitString(splitString.Length - 2).ToString() &lt;&gt; splitString(streetMarkerIndex + 1) Then\n            For counter As Integer = streetMarkerIndex To splitString.Length - 2\n                sb.Append(splitString(counter) + " ")\n            Next counter\n        End If\n    Else\n        For counter As Integer = 0 To addressIndex - 1\n            sb.Append(splitString(counter) + " ")\n        Next counter\n    End If\n    address2 = RTrim(sb.ToString())\n\n    Dim output As New Collection\n    output.Add(address1, "Address1")\n    output.Add(address2, "Address2")\n    output.Add(city, "City")\n    output.Add(state, "State")\n    output.Add(zip, "Zip")\n    Return output\nEnd Function\n\nPrivate Function getLastIndexOf(ByVal sArray As String(), ByVal checkArray As String()) As Integer\n    Dim sourceIndex As Integer = 0\n    Dim outputIndex As Integer = 0\n    For Each item As String In checkArray\n        For Each source As String In sArray\n            If source.ToLower = item.ToLower Then\n                outputIndex = sourceIndex\n                If item.ToLower = "box" Then\n                    outputIndex = outputIndex + 1\n                End If\n            End If\n            sourceIndex = sourceIndex + 1\n        Next\n        sourceIndex = 0\n    Next\n    Return outputIndex\nEnd Function\n</code></pre>\n\n<p>Passing the <code>parseAddress</code> function "A. P. Croll &amp; Son  2299 Lewes-Georgetown Hwy, Georgetown, DE 19947" returns:</p>\n\n<blockquote>\n<pre><code>2299 Lewes-Georgetown Hwy\nA. P. Croll &amp; Son  \nGeorgetown\nDE\n19947\n</code></pre>\n</blockquote>\n'}, {'answer_id': 16887, 'author': 'James A. Rosen', 'author_id': 1190, 'author_profile': 'https://Stackoverflow.com/users/1190', 'pm_score': 7, 'selected': False, 'text': '<p>I think outsourcing the problem is the best bet: send it to the Google (or Yahoo) geocoder.  The geocoder returns not only the lat/long (which aren\'t of interest here), but also a rich parsing of the address, with fields filled in that you didn\'t send (including ZIP+4 and county).</p>\n\n<p>For example, parsing "1600 Amphitheatre Parkway, Mountain View, CA" yields</p>\n\n<pre><code>{\n  "name": "1600 Amphitheatre Parkway, Mountain View, CA, USA",\n  "Status": {\n    "code": 200,\n    "request": "geocode"\n  },\n  "Placemark": [\n    {\n      "address": "1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA",\n      "AddressDetails": {\n        "Country": {\n          "CountryNameCode": "US",\n          "AdministrativeArea": {\n            "AdministrativeAreaName": "CA",\n            "SubAdministrativeArea": {\n              "SubAdministrativeAreaName": "Santa Clara",\n              "Locality": {\n                "LocalityName": "Mountain View",\n                "Thoroughfare": {\n                  "ThoroughfareName": "1600 Amphitheatre Pkwy"\n                },\n                "PostalCode": {\n                  "PostalCodeNumber": "94043"\n                }\n              }\n            }\n          }\n        },\n        "Accuracy": 8\n      },\n      "Point": {\n        "coordinates": [-122.083739, 37.423021, 0]\n      }\n    }\n  ]\n}\n</code></pre>\n\n<p>Now <em>that\'s</em> parseable!</p>\n'}, {'answer_id': 852970, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>RecogniContact is a Windows COM object that parses US and European addresses. You can try it right on \n<a href="http://www.loquisoft.com/index.php?page=8" rel="nofollow noreferrer">http://www.loquisoft.com/index.php?page=8</a></p>\n'}, {'answer_id': 2222364, 'author': 'We Know', 'author_id': 263710, 'author_profile': 'https://Stackoverflow.com/users/263710', 'pm_score': 3, 'selected': False, 'text': '<p>Try <a href="http://www.address-parser.com" rel="noreferrer">www.address-parser.com</a>. We use their web service, which you can test online</p>\n'}, {'answer_id': 3738624, 'author': 'weston', 'author_id': 68655, 'author_profile': 'https://Stackoverflow.com/users/68655', 'pm_score': 3, 'selected': False, 'text': '<p>+1 on James A. Rosen\'s suggested solution as it has worked well for me, however for completists this site is a fascinating read and the best attempt I\'ve seen in documenting addresses worldwide: <a href="http://www.columbia.edu/kermit/postal.html" rel="nofollow noreferrer">http://www.columbia.edu/kermit/postal.html</a></p>\n'}, {'answer_id': 3836235, 'author': 'Shawn', 'author_id': 157949, 'author_profile': 'https://Stackoverflow.com/users/157949', 'pm_score': 1, 'selected': False, 'text': "<p>I don't know HOW FEASIBLE this would be, but I haven't seen this mentioned so I thought I would go ahead and suggest this:</p>\n\n<p>If you are strictly in the US... get a huge database of all zip codes, states, cities and streets. Now look for these in your addresses. You can validate what you find by testing if, say, the city you found exists in the state you found, or by checking if the street you found exists in the city you found. If not, chances are John isn't for John's street, but is the name of the addressee... Basically, get the most information you can and check your addresses against it.\nAn extreme example would be to get A LIST OF ALL THE ADDRESSES IN THE US OF A and then find which one has the most relevant match to each of your addresses...</p>\n"}, {'answer_id': 4767879, 'author': 'anand', 'author_id': 585587, 'author_profile': 'https://Stackoverflow.com/users/585587', 'pm_score': 2, 'selected': False, 'text': '<p>Since there is chance of error in word, think about using SOUNDEX combined with LCS algorithm to compare strings, this will help a lot !</p>\n'}, {'answer_id': 7775154, 'author': 'CoolDude', 'author_id': 996394, 'author_profile': 'https://Stackoverflow.com/users/996394', 'pm_score': 2, 'selected': False, 'text': '<p>You might want to check this out!! <a href="http://jgeocoder.sourceforge.net/parser.html" rel="nofollow">http://jgeocoder.sourceforge.net/parser.html</a>\nWorked like a charm for me.</p>\n'}, {'answer_id': 8627009, 'author': 'Nicholas Piasecki', 'author_id': 32187, 'author_profile': 'https://Stackoverflow.com/users/32187', 'pm_score': 5, 'selected': False, 'text': '<p>The original poster has likely long moved on, but I took a stab at porting the Perl <a href="http://search.cpan.org/~timb/Geo-StreetAddress-US-1.03/US.pm">Geo::StreetAddress:US</a> module used by <a href="http://geocoder.us/">geocoder.us</a> to C#, dumped it on CodePlex, and think that people stumbling across this question in the future may find it useful:</p>\n\n<p><a href="http://usaddress.codeplex.com/">US Address Parser</a></p>\n\n<p>On the project\'s home page, I try to talk about its (very real) limitations. Since it is not backed by the USPS database of valid street addresses, parsing can be ambiguous and it can\'t confirm nor deny the validity of a given address. It can just try to pull data out from the string.</p>\n\n<p>It\'s meant for the case when you need to get a set of data mostly in the right fields, or want to provide a shortcut to data entry (letting users paste an address into a textbox rather than tabbing among multiple fields). It is <em>not</em> meant for verifying the deliverability of an address.</p>\n\n<p>It doesn\'t attempt to parse out anything above the street line, but one could probably diddle with the regex to get something reasonably close--I\'d probably just break it off at the house number.</p>\n'}, {'answer_id': 12797231, 'author': 'komal', 'author_id': 1730707, 'author_profile': 'https://Stackoverflow.com/users/1730707', 'pm_score': 2, 'selected': False, 'text': '<p>using google API</p>\n\n<pre><code>$d=str_replace(" ", "+", $address_url);\n$completeurl ="http://maps.googleapis.com/maps/api/geocode/xml?address=".$d."&amp;sensor=true"; \n$phpobject = simplexml_load_file($completeurl);\nprint_r($phpobject);\n</code></pre>\n'}, {'answer_id': 16448034, 'author': 'Matt', 'author_id': 1048862, 'author_profile': 'https://Stackoverflow.com/users/1048862', 'pm_score': 4, 'selected': False, 'text': '<p>SmartyStreets has a new feature that extracts addresses from arbitrary input strings. (Note: I don\'t work at SmartyStreets.)</p>\n<p>It successfully extracted all addresses from the sample input given in the question above. (By the way, only 9 of those 10 addresses are valid.)</p>\n<p>Here\'s some of the output:<img src="https://i.stack.imgur.com/1Y0Gu.png" alt="enter image description here" /></p>\n<p>And here\'s the CSV-formatted output of that same request:</p>\n<pre><code>ID,Start,End,Segment,Verified,Candidate,Firm,FirstLine,SecondLine,LastLine,City,State,ZIPCode,County,DpvFootnotes,DeliveryPointBarcode,Active,Vacant,CMRA,MatchCode,Latitude,Longitude,Precision,RDI,RecordType,BuildingDefaultIndicator,CongressionalDistrict,Footnotes\n1,32,79,&quot;2299 Lewes-Georgetown Hwy, Georgetown, DE 19947&quot;,N,,,,,,,,,,,,,,,,,,,,,,\n2,81,119,&quot;11522 Shawnee Road, Greenwood DE 19950&quot;,Y,0,,11522 Shawnee Rd,,Greenwood DE 19950-5209,Greenwood,DE,19950,Sussex,AABB,199505209226,Y,N,N,Y,38.82865,-75.54907,Zip9,Residential,S,,AL,N#\n3,121,160,&quot;144 Kings Highway, S.W. Dover, DE 19901&quot;,Y,0,,144 Kings Hwy,,Dover DE 19901-7308,Dover,DE,19901,Kent,AABB,199017308444,Y,N,N,Y,39.16081,-75.52377,Zip9,Commercial,S,,AL,L#\n4,190,232,&quot;2 Penns Way Suite 405 New Castle, DE 19720&quot;,Y,0,,2 Penns Way Ste 405,,New Castle DE 19720-2407,New Castle,DE,19720,New Castle,AABB,197202407053,Y,N,N,Y,39.68332,-75.61043,Zip9,Commercial,H,,AL,N#\n5,247,285,&quot;33 Bridle Ridge Court, Lewes, DE 19958&quot;,Y,0,,33 Bridle Ridge Cir,,Lewes DE 19958-8961,Lewes,DE,19958,Sussex,AABB,199588961338,Y,N,N,Y,38.72749,-75.17055,Zip7,Residential,S,,AL,L#\n6,306,339,&quot;2742 Pulaski Hwy Newark, DE 19711&quot;,Y,0,,2742 Pulaski Hwy,,Newark DE 19702-3911,Newark,DE,19702,New Castle,AABB,197023911421,Y,N,N,Y,39.60328,-75.75869,Zip9,Commercial,S,,AL,A#\n7,341,378,&quot;2284 Bryn Zion Road, Smyrna, DE 19904&quot;,Y,0,,2284 Bryn Zion Rd,,Smyrna DE 19977-3895,Smyrna,DE,19977,Kent,AABB,199773895840,Y,N,N,Y,39.23937,-75.64065,Zip7,Residential,S,,AL,A#N#\n8,406,450,&quot;1500 Serpentine Road, Suite 100 Baltimore MD&quot;,Y,0,,1500 Serpentine Rd Ste 100,,Baltimore MD 21209-2034,Baltimore,MD,21209,Baltimore,AABB,212092034250,Y,N,N,Y,39.38194,-76.65856,Zip9,Commercial,H,,03,N#\n9,455,495,&quot;580 North Dupont Highway Dover, DE 19901&quot;,Y,0,,580 N DuPont Hwy,,Dover DE 19901-3961,Dover,DE,19901,Kent,AABB,199013961803,Y,N,N,Y,39.17576,-75.5241,Zip9,Commercial,S,,AL,N#\n10,497,525,&quot;P.O. Box 778 Dover, DE 19903&quot;,Y,0,,PO Box 778,,Dover DE 19903-0778,Dover,DE,19903,Kent,AABB,199030778781,Y,N,N,Y,39.20946,-75.57012,Zip5,Residential,P,,AL,\n</code></pre>\n<p>I was the developer who originally wrote the service. The algorithm we implemented is a bit different from any specific answers here, but each extracted address is verified against the address lookup API, so you can be sure if it\'s valid or not. Each verified result is guaranteed, but we know the other results won\'t be perfect because, as has been made <em>abundantly clear</em> in this thread, addresses are unpredictable, even for humans sometimes.</p>\n'}, {'answer_id': 19735415, 'author': 'Sachin Prasad', 'author_id': 2840147, 'author_profile': 'https://Stackoverflow.com/users/2840147', 'pm_score': 2, 'selected': False, 'text': '<p>For  ruby or rails developers there is a nice gem available called <a href="https://github.com/derrek/street-address" rel="nofollow">street_address</a>. \nI have been using this on one of my project and it does the work I need.</p>\n\n<p>The only Issue I had was whenever an address is in this format <code>P. O. Box 1410 Durham, NC 27702</code>  it returned nil and therefore I had to replace "P. O. Box" with \'\' and after this it were able to parse it. </p>\n'}, {'answer_id': 26139807, 'author': 'Kim Ryan', 'author_id': 4098466, 'author_profile': 'https://Stackoverflow.com/users/4098466', 'pm_score': 2, 'selected': False, 'text': '<p>This type of problem is hard to solve because of underlying ambiguities in the data.</p>\n\n<p>Here is a Perl based solution that defines a recursive descent grammar tree based on regular expressions to parse many valid combination of street addresses: <a href="http://search.cpan.org/~kimryan/Lingua-EN-AddressParse-1.20/lib/Lingua/EN/AddressParse.pm" rel="nofollow">http://search.cpan.org/~kimryan/Lingua-EN-AddressParse-1.20/lib/Lingua/EN/AddressParse.pm</a> . This includes sub properties within an address such as:\n12 1st Avenue N Suite # 2 Somewhere CA 12345 USA</p>\n\n<p>It  is similar to <a href="http://search.cpan.org/~timb/Geo-StreetAddress-US-1.03/US.pm" rel="nofollow">http://search.cpan.org/~timb/Geo-StreetAddress-US-1.03/US.pm</a> mentioned above, but also works for addresses that are not from the USA, such as the UK, Australia and Canada.</p>\n\n<p>Here is the output for one of your sample addresses. Note that the name section would need to be removed first from "A. P. Croll &amp; Son 2299 Lewes-Georgetown Hwy, Georgetown, DE 19947" to reduce it to "2299 Lewes-Georgetown Hwy, Georgetown, DE 19947". This is easily achieved by removing all data up to the first number found in the string.</p>\n\n<pre><code>Non matching part       \'\'\nError                   \'0\'\nError descriptions      \'\'\nCase all                \'2299 Lewes-Georgetown Hwy Georgetown DE 19947\'\nCOMPONENTS              \'\'\ncountry                 \'\'\npo_box_type             \'\'\npost_box                \'\'\npost_code               \'19947\'\npre_cursor              \'\'\nproperty_identifier     \'2299\'\nproperty_name           \'\'\nroad_box                \'\'\nstreet                  \'Lewes-Georgetown\'\nstreet_direction        \'\'\nstreet_type             \'Hwy\'\nsub_property_identifier \'\'\nsubcountry              \'DE\'\nsuburb                  \'Georgetown\'\n</code></pre>\n'}, {'answer_id': 27454605, 'author': 'hassansin', 'author_id': 1807881, 'author_profile': 'https://Stackoverflow.com/users/1807881', 'pm_score': 1, 'selected': False, 'text': '<p>There is javascript port of perl Geo::StreetAddress::US package: <a href="https://github.com/hassansin/parse-address" rel="nofollow">https://github.com/hassansin/parse-address</a> . It\'s regex-based and works fairly well.</p>\n'}]
['https://Stackoverflow.com/questions/16413', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/149/']