Search code examples
rubyregexstreet-address

stripping street numbers from street addresses


Using Ruby (newb) and Regex, I'm trying to parse the street number from the street address. I'm not having trouble with the easy ones, but I need some help on:

'6223 1/2 S FIGUEROA ST' ==> 'S FIGUEROA ST'

Thanks for the help!!

UPDATE(s):

'6223 1/2 2ND ST' ==> '2ND ST'

and from @pesto '221B Baker Street' ==> 'Baker Street'


Solution

  • This will strip anything at the front of the string until it hits a letter:

    street_name = address.gsub(/^[^a-zA-Z]*/, '')
    

    If it's possible to have something like "221B Baker Street", then you have to use something more complex. This should work:

    street_name = address.gsub(/^((\d[a-zA-Z])|[^a-zA-Z])*/, '')