http://www.perlmonks.org?node_id=11131194

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi there Monks!

I have this line in my code and I am trying to see if there is a way to add more than one file match in this line, the files comes as "*.txt", "*.TXT", "*.png", "*.PNG".
It breaks if in this line the file extension is "*.TXT" instead of "*.txt".
my @files = $zip->membersMatching( '.*\.txt' );

Thanks for looking!

Replies are listed 'Best First'.
Re: Archive::Zip matching different file extension
by haukex (Archbishop) on Apr 13, 2021 at 15:32 UTC

    I assume you meant Archive::Zip instead of XML::XPath? At least according to the documentation, this should work: my @files = $zip->membersMatching( qr/\.(?:txt|png)$/i );

      Thank you!!
        FYI, in the Perl world it is very common to find that – for your convenience – a library will accept either a string-pattern or a regular expression as an argument. Regular expressions, as haukex just demonstrated, are by far the most powerful alternative.