Don't see how your regex could do what you say. Your "^(\d)$" is looking for a SINGLE digit between start of record/string, "^," and the end of same, "$."
What follows sorta' does what you're talking about altho in the regex you'll need to do "(012346" rather than "(\d{6}" or some variant of (any digit except 5,7, 8 or 9) or similarly clunky approaches to deal with the exact string
and, is this homework? If so, it's a good idea to mention ('fess up) that fact, so monks can teach without actually DOING the homework.
#!C:/perl/bin -w
use strict;
use vars qw ($input @input @img $img);
@input = <DATA> ;
foreach $input (@input) {
if ( $input =~ # Caret in next line: Start at begining of
+string/record/whatever
/^(\d{6} # sTART CAPTURE, with any digit, [0-9]
+, exactly six times.
(- # optionally (trailing "?") in a NON
+-capture-group: a dash followed by a
\w{3})? # word char, exactly 3 times; end group
+ing parens
\.jpg$ # literal period followed by "jpg" endin
+g the string
) # end capture
/ix ) { #case insensitive (to catch -all and -
+EXP); extended form
push(@img, $input);
}
}
print "\n\t+++++\n";
print @img;
print "\n\tdone\n";
exit;
__DATA__
012346.jpg
012346-all.jpg
012346-EXP.jpg
012346-exp.jpg
012346-ALL.jpg
012345.jpg
12345.jpg
01234.jpeg
0123345+ALL.jpg
0123345-exp.jpg
0123345-ALL.jpg
not_jpg.last
note that the last 6 items in data do NOT match the regex. |