From: Igor Sutton Lopes <[EMAIL PROTECTED]>
> On 2007/03/14, at 16:00, yitzle wrote:
>
> > regex.
> > if ( m/^https?\/\/:blah\.com/)
>
> <code>
> my @possible_values = qw{
> http://www.google.com
> https://my.domain.
> http://some.other.domain.net
> };
>
> my @urls = qw{
> http://www.google.com/?some_bizarre_args
> https://my.domain.com
> https://my.domain.net
> http://some.other.domain.net
> };
>
> my $regex = '(' . join( "|", @possible_values ) . ')';
>
> foreach my $url (@urls) {
> if ( $url =~ /$regex/ ) {
> print "$url matches!\n";
> }
> }
> </code>
Try to match a URL like this:
http://wwwXgoogle.com/?some_bizarre_args
It matches, doesn't it? Bummer.
Try
my $regex = '(' . join( "|", map quotemeta($_), @possible_values ) .
')';
instead. Plus you may want to make the match case insensitive. Host
names ARE case insensitive.
Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/