使用带有array_diff()的正则表达式来排除具有给定扩展名的文件

I echo out a directory's contents, excluding some files like this:

$exclude_list = array(".", "..", "index.php",".htaccess");
$scanned_directory = array_diff(scandir($dir), $exclude_list);   

I would like to add all the files in the directory with the extension .meta.js to the exclude list. Can I do that with a regex, or would I have to loop through them and add them to the array individually, or is there some other way?

Using preg_grep with a regex would be suitable to filter your list.

 preg_grep("/^(\.|\.\.|index\.php|\.htaccess)$|\.meta\.js$/",
     $scanned_dirs, PREG_GREP_INVERT)

This covers your existing excludes, as well as the meta extension.