[0-9]+.txt没有';似乎没有将文本文件与数字名称相匹配


[0-9]+.txt doesn't seem to be matching text files with numeric names

此模式似乎无法正确匹配具有数字名称的txt文件:[0-9]+.txt
有人能告诉我我做错了什么吗?

上下文:$posts = preg_grep("[0-9]+.txt", glob('posts/*.txt'));

您的表达式缺少分隔符:

'~/[0-9]+'.txt$~'

但将这个需求添加到glob()本身可能更容易:

$posts = glob('posts/[0-9]*.txt');