How do I write a Perl regular express to find out if a filename cont开发者_开发问答ains a specific extension, for example ".pdf". The filename can be anything.
Something like this?
if ($filename =~ /\.pdf$/) {
// Do stuff
}
Test the filename using the following regular expression: \.pdf$
You don't, explode/split on the . and use the last item in the array/collection. This is usally better/faster than using a regex.
精彩评论