On Wed, Mar 11, 2009 at 12:53, howa <howac...@gmail.com> wrote:
> Hello,
>
> On Mar 12, 12:34 am, jimsgib...@gmail.com (Jim Gibson) wrote:
>> That will test if $a starts with 'html' or 'jpg'. To test for a non-match,
>> use the !~ operator:
>>
>
> I can't, since I will add more criteria into the regex,
>
> e.g.
>
> I need to match a.* , except a.html or a.jpg
>
>  if ( $a =~ /a\.(?:html|jpg)$/i ) # of course this one does not work.
snip

You want a zero-width-negative-look-ahead:

#!/usr/bin/perl

use strict;
use warnings;

my @a = qw/a.html a.jpg a.gif/;

for my $s (@a) {
        print "$s ", $s =~ /a[.](?!html|jpg)/ ? "matches" : "does not match",
                "\n";
}

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
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