What are the advantages and disadvantages of using regular expressions with preg_match to check for file existence in PHP?

When using regular expressions with preg_match to check for file existence in PHP, the advantage is that you can have more flexibility in defining patterns for file names. However, the disadvantage is that regular expressions can be complex and may not be necessary for simple file existence checks. It is important to balance the need for flexibility with the simplicity of the solution.

$filename = 'example.txt';

if (preg_match('/^[a-zA-Z0-9_]+\.(txt|csv)$/', $filename)) {
    if (file_exists($filename)) {
        echo "File exists!";
    } else {
        echo "File does not exist.";
    }
} else {
    echo "Invalid file name format.";
}