On 01/28/2013 02:57 PM, Angela Barone wrote:
Hello,

        I'm trying to abbreviate ordinals(?) that occur only in the middle of 
an address and I'm having a problem.  The line below works:

$test_data =~ s/(\S) North (\S)/$1 N. $2/i;

however, if the address is something like 901 North St., it abbreviates that as 
well.  I'm wanting it to work only on an address like
53 North Benson St. -> 53 N. Benson St.

        Is there a way to know whether or not 'North' is a street name as opposed to a 
direction, or am I asking too much?  I was thinking of counting the number of 
"words" between "North' and 'St.' (and if it's zero then don't do it), but I 
wouldn't know how to do that or even if that's the best way to do it.

Thanks!
Angela
Angela,

This worked for me:

  $test_data =~ s/(\S) North (\S+\s[^.]+\.)/$1 N. $2/;

It assumes that the address ends in an abbreviation such as Rd., St., Ave., etc.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to