Win8 Strawberry 5.8.9.5 (32) Fri 08/11/2023 14:59:13 C:\@Work\Perl\monks >perl use strict; use warnings; use Test::More; use Test::NoWarnings; my @Tests = ( 'ALL these should match', # match # string success [ '.htm' => 1, ], [ 'dp198076_424b2-us2342673.htm' => 1, ], [ 'fizz dp198076_424b2-us2342673.htm fuzz' => 1, ], 'NONE of these should match', [ '' => '', ], [ ' ' => '', ], [ 'xxx' => '', ], [ "\n\n\n" => '', ], [ 'dp198076_424b2-us2342673.htm dp198076_exfilingfees.htm' => '', ], [ '.htmfred' => '', ], # see pm#11153807 [ 'fizz dp198076_424b2-us2342673.htm foo bar dp198076_exfilingfees.htm fuzz' => '', ], [ 'fizz dp198076_424b2-us2342673.htm foo xxx.htm bar dp198076_exfilingfees.htm fuzz' => '', ], [ 'xxx.htmyyy.htm' => '', ], [ '.htm.htm' => '', ], ); # end @Tests my @additional = qw(Test::NoWarnings); # each of these adds 1 test plan 'tests' => (scalar grep { ref eq 'ARRAY' } @Tests) + @additional ; my $rx_once = qr{ (?: (?! [.]htm) .)* [.]htm \b }xms; VECTOR: for my $ar_vector (@Tests) { if (not ref $ar_vector) { note $ar_vector; next VECTOR; } my ($string, $expected) = @$ar_vector; my $got = $string =~ m{ \A (?: (?! $rx_once) .)* # no match before single match $rx_once # match just once (?: (?! $rx_once) .)* # no match after single match \Z }xms; is $got, $expected; } # end for VECTOR ^Z 1..14 # ALL these should match ok 1 ok 2 ok 3 # NONE of these should match ok 4 ok 5 ok 6 ok 7 ok 8 ok 9 ok 10 ok 11 ok 12 ok 13 ok 14 - no warnings