ezekieldas has asked for the wisdom of the Perl Monks concerning the following question:
@files includes (I'd like to match all of these): "__asdf.jpg asdf.jp +g FOO.AVI Hjz-6Nj.JPG this is[myfile].jpg" foreach my $file( @files ) { # I've tried various "character classes (w, W, d, D...), # combinations of anchoring, not anchoring, using + # I'm not getting consistent matches. At best the below # gives me most files but Hjz-6Nj gets "$1 = Hjz" I lose # the hyphen. # # And for $2, when I have a list of extensions like this # is there a sort of array I can place them in? And # what about camel case extensions? This long list seems # really innefficent. if ( $file =~ /(\w+|W).(jpg|JPG|gif|GIF|wmv|WMV|mpg|MPG|avi|AVI)$/ ) + { my $prefix = $1; my $ext = $2; print "prefix: [$prefix]\n"; print "ext: [$ext]\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: matching and backreferencing filenames
by jethro (Monsignor) on Sep 30, 2011 at 16:46 UTC | |
|
Re: matching and backreferencing filenames
by Lotus1 (Vicar) on Sep 30, 2011 at 17:58 UTC | |
|
Re: matching and backreferencing filenames
by ezekieldas (Initiate) on Oct 03, 2011 at 22:06 UTC |