I am trying to work up a regular expression that will capture the file name from the following output. This is to be used in a Perl routine to capture filenames from within a Zip file. (There may be modules that will do what I need, but I cannot install them on the system and because of the way things are run, it would not be a good idea to run them out of my home directory so Extra modules are not an option at this point in time). The data would look like this:

0 Stored 0 0% 04-20-05 08:43 00000000 test 1 2 3.z +ip 704106 DeflatN 83362 89% 04-04-05 19:00 8e76dc22 file1.dat

What I need to get out would be the file name, so in the first example, it would be "test 1 2 3.zip" and in the second "file1.dat." If I knew there would never be spaces in the names, no problem, but thats not something I can guarantee. Also, file names might be in a mix of upper and lower case. What I have come up with is the following (untested as of yet):

$line =~ /\d\s{1,2}\w{6,7}\s{1,}%\s{2}\d{2}-\d{2}-\d{2}\s{2}\d{2}:\d{2 +}\s{2}\w{8}\s{1,}(\w {1,}\.\w{3})/; push @temp, $1;

This would be nested inside of a foreach loop that loops through a temp file containing the data. @temp is then returned back to the main script calling this function. My main question is in looking for a better way to handle the regular expression match.

Any ideas would be welcome. Thanks


In reply to Regular Expressions Matching with Perl by nimdokk

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.