-3

2224 Mission Street San Francisco CA 94110

The string should be split into :

StreetName : 2224 Mission Street

City: San Francisco

state: CA

zip: 94110

rgettman
  • 176,041
  • 30
  • 275
  • 357
Julius
  • 19
  • 4
  • 1
    And what is your code so far? or are you expecting that SO users code you a solution from scratch? – taxicala Jun 05 '15 at 20:24
  • 1
    possible duplicate of [How to parse freeform street/postal address out of text, and into components](http://stackoverflow.com/questions/11160192/how-to-parse-freeform-street-postal-address-out-of-text-and-into-components) – Chris Stillwell Jun 05 '15 at 20:25
  • You can simply find by regex street number, state and zip. But without list of cities you aren't able to divide `Mission Street San Francisco` into two items as you need. If I suppose `street` shouldn't be in the street name. – pavel Jun 05 '15 at 20:27
  • var addr = $['address2']['value']; var postal = /\d+$/g.exec(addr); var region = /[A-Z]+/g.exec(addr); – Julius Jun 05 '15 at 20:33

1 Answers1

0
var address = ("2224 Mission Street San Francisco CA 94110").trim().replace(" ",""),
zip = address.substring(address.length-5, address.length), //provided zip in at the end of the string and it's 5 digit.
state = address.substring(address.length-7, address.length-5)// provided state contains two characters;

But is there any rule to divide street & ciry?

Indranil Mondal
  • 2,799
  • 3
  • 25
  • 40
  • No, i got my zip and state name but can't figure out how I can get city and street name. also if city name is chicago, how would I do tht. – Julius Jun 05 '15 at 20:38
  • If you assure the "street" text will be there with the street name then it's possible otherwise impossible. – Indranil Mondal Jun 05 '15 at 20:41