in reply to Re^3: Search for text from user input
in thread Search for text from user input

Warning about the above for the future reader:

Both regexen were originally written without the /i. Then (belatedly) recognition of the need for case insensitivity on the file extension set in. /me (insufficient thought) just added /i... without fixing the rest of the regexen.

Duh. That kind of thoughtlessness during late-night (or early morning) code revision has bit me before. Perhaps this will warn others.

The regexen don't need the a-z when the i is added. Obvious? Yes, but not at the (befuddled) time.

And the second version would be better and more clearly written with a negated match:  if ($item !~/^[A-Z0-9]+\.jpg$/i) {

Tested:

#!/usr/bin/perl use strict; use warnings; # 839761 my @foo=("a.jpg", "b.txt", "Cde.jpg", "abc.jpg.delete_everything.exe", + "123.jpg", "|#&.exe"); print "Using negative match, '!~'- items which match should be exclude +d:\n\n"; for my $item(@foo) { if ($item !~/^[A-Z0-9]+\.jpg$/i) { print "\t--> (negated) match: $item \n"; }else{ print "no match in \$item: $item \n"; } } print "\n\n". 'Now using /^[A-Z0-9]+\..+$/i' . " so matched should be +accepted: \n\n"; for my $item(@foo) { if ($item =~/^[A-Z0-9]+\.jpg$/i) { print "\t --> match: $item \n"; }else{ print "no match in \$item: $item \n"; } }