开发者

How do I write an regular express to find out if a filename contains ".pdf" at the end of the filename?

开发者 https://www.devze.com 2023-03-28 10:37 出处:网络
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?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消