Unless you have special requirements concerning the "file extension", pathinfo is a better solution than regular expressions because it is more descriptive of what is happening (assuming you use the named constant), and the reader does not need to check the regex pattern.