Greg Bacon schreef: > #! /usr/bin/perl > > use warnings; > use strict; > > use constant { > MATCH => 1, > NO_MATCH => 0, > }; > > my @tests = ( > [ "winter tire", => MATCH ], > [ "tire", => MATCH ], > [ "retire", => MATCH ], > [ "tired", => MATCH ], > [ "snowbird tire", => MATCH ], > [ "tired on a snow day", => MATCH ], > [ "snow tire and regular tire", => MATCH ], > [ " tire" => MATCH ], > [ "snow tire" => NO_MATCH ], > [ "snow tire" => NO_MATCH ], > [ "some snowtires" => NO_MATCH ], > ); > [...]
I negated the test, to make the regex simpler: my $snow_tire = qr/ snow [[:blank:]]* tire (?!.*tire) /x; my $fail; for (@tests) { my($str,$want) = @$_; my $got = $str !~ /$snow_tire/; my $pass = !!$want == !!$got; print "$str: ", ($pass ? "PASS" : "FAIL"), "\n"; ++$fail unless $pass; } print "\n", (!$fail ? "PASS" : "FAIL"), "\n"; __END__ -- Affijn, Ruud "Gewoon is een tijger." -- http://mail.python.org/mailman/listinfo/python-list