(Warning: more Regexp::Assemble pimping ahead).

Assuming you do not really care about those captures, if I "unroll" the patterns, it looks like you're interested matching against the following patterns:

^\d{8}\.ilf ^\d{8}_\d+\.ilf ^\d{8}\.sht ^\d{8}\s\d+\.sht

Using the assemble script from the above module, or something like

my $re = Regexp::Assemble->new(flags=>'i')->add(@list)

it produces the following pattern:

^\d{8}(?:\.(?:ilf|sht)|\s\d+\.sht|_\d+\.ilf)

... which looks roughly like that the other people came up with manually. If you do need the captures, the pattern becomes

^\d{8}(?:(\s(\d+))\.sht|(_(\d+))\.ilf|\.(?:ilf|sht))

in which case you can perform the match and get the captures with something like

my @result = map {defined} ($file =~ /$re/);

• another intruder with the mooring in the heart of the Perl


In reply to Re: File name regex by grinder
in thread File name regex by dev2dev

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.