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.

In reply to Re: regex help by ww
in thread regex help by calypso

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.