I pulled a face the instant I caught sight of your ^.*(\..*)$ regex: the leading ^.* looks pretty pointless, the trailing (\..*) overly generic. For some background on where I'm coming from see the classic old node from 2000: Death to Dot Star! by Ovid.
Given you say "the image is guaranteed to end with the picture extension" I would write it something like: /\.([^.]+)$/ or /\.([a-zA-Z0-9]+)$/ or /\.(\w+)$/ or some such, depending on your requirements, the point being to be more precise than the dreaded "dot star". To illustrate, using GrandFather's example test program:
produces:use strict; use warnings; my @tests = ( ".", "", "A sentence.", ".gitignore", "word.doc", "a.dotted.name", ); print /\.([^.]+)$/ ? "Matched '$1' in " : "Failed", " '$_'\n" for @tes +ts;
Failed '.' Failed '' Failed 'A sentence.' Matched 'gitignore' in '.gitignore' Matched 'doc' in 'word.doc' Matched 'name' in 'a.dotted.name'
If you give us a lot more specific examples of strings that should match and ones that shouldn't, we can offer a more precise regex.
See also: Rosetta code
Update: For an alternative to regexes, using instead mostly standard Perl facilities, such as glob, opendir, readdir, File::Glob, File::Basename, File::Copy, File::Spec, Path::Tiny and Path::Class::Dir, see:
In reply to Re: My regex works, but I want to make sure it's not blind luck
by eyepopslikeamosquito
in thread My regex works, but I want to make sure it's not blind luck
by SergioQ
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |