正则表达式帮助:匹配以下划线开头的任何图像文件

Sco*_*t B 2 php regex

下面的语句将加载所有不以下划线字符开头的图像...

if (!is_dir($file) && preg_match("/^[^_].*\.(bmp|jpeg|gif|png|jpg)$/i", $file)) 
Run Code Online (Sandbox Code Playgroud)

我需要修改它,以便它只加载带有下划线的DO BEGIN图像.

Ale*_*own 7

只需删除字符集上的否定:[^_]变为_:

if (!is_dir($file) && preg_match("/^_.*\.(bmp|jpeg|gif|png|jpg)$/i", $file)) 
Run Code Online (Sandbox Code Playgroud)