in reply to Regular Expressions Matching with Perl

Regexen should be a short as possible, but no shorter.

my( $file ) = /[[:hexdigit:]]{8}\s+(.*)$/;

Replies are listed 'Best First'.
Re^2: Regular Expressions Matching with Perl
by ikegami (Patriarch) on Apr 20, 2005 at 17:49 UTC

    Too short. That fails if the file size is 10,000,000 bytes or more.
    my ($file) = $line =~ /:.{15}(.*)/;
    would be minimal.

      Erm, it's matching against the 8 hex digits of the CRC-32. How is that affected by the file size? Granted on further examination of unzip -v output it should be anchored off the date as well.

      /:\d\d\s\s[[:hexdigit:]]{8}\s\s(.*)$/
        Erm, it's matching against the 8 hex digits of the CRC-32. How is that affected by the file size?

        If the file size is 10000000 bytes or higher, your original regexp will not match against the 8 digits of the CRC-32 as you say. Instead, it will match against the 8 digits of the file size, because they come earlier. That's why I used the date as the anchor.