wrote in news:7d880468-1391-46f5-9522-6d244ca57b29
@h20g2000yqn.googlegroups.com:
> I'm trying to come up with a Perl regexp to capture multiple
> capitalized words in a row.
>
> For example, in the sentence "I love New York City in the springtime."
>
> I want to capture "New York City", "New York", and "York City".
>
> I've been playing around with this for awhile with little luck. Any
> ideas?
Here is one part of the task:
#!/usr/bin/perl
use strict;
use warnings;
my $text = <<EOT;
I love New York City in the springtime. The United Nations
is headquartered in New York City but the North Atlantic Treaty
Organization is headquartered in Brussels.
EOT
my $pat = '(?:[[:upper:]][[:alpha:]]+)';
my @matches = ( $text =~ /\s(${pat}(?:\s+${pat})+)/g );
for ( @matches ) {
s/\s+/ /g;
print $_, "\n";
}
__END__
C:\DOCUME~1\asu1\LOCALS~1\Temp> t
New York City
The United Nations
New York City
North Atlantic Treaty Organization
--
A. Sinan Unur <>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/