Removing street numbers from street addresses

Using Ruby (newb) and Regex, I am trying to parse a street number from a street address. I have no lung problems, but I need help:

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

Thanks for the help!

UPDATE (s):

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

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

+3
source share
7 answers

This will remove anything at the front of the line until it hits the letter:

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

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

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

:

.*\d\s(.*)

:

.*\d.*?\s(.*)

123A Street Name

( ), . (. *)

+2

stackoverflow: , , ,

, google/yahoo , , / - , ,

+1

? .

1234 45TH ST

1234 45 ST

, .

, , , . Ruby, Perl, :

#!/usr/bin/perl

use strict;
use warnings;

my @addrs = (
    '6223 1/2 S FIGUEROA ST',
    '1234 45TH ST',
    '1234 45 ST',
);

for my $addr ( @addrs ) {
    my @parts = split / /, $addr;

    while ( @parts ) {
        my $part = shift @parts;
        if ( $part =~ /[A-Z]/ ) {
            print join(' ', $part, @parts), "\n";
            last;
        }
    }
}

C:\Temp> skip
S FIGUEROA ST
45TH ST
ST
+1

! , . , " ", , , :

  • RR 2 15 (RR Rural Route, HC, HCR ..).
  • PO Box 17
  • 12B-7A
  • NW95E235
  • .

. , , - . , .

SmartyStreets. API - -, , , , / , .

+1

/[^\d]+$/ , .

0

Source: https://habr.com/ru/post/1710768/


All Articles