错误 preg_match - php

Wrong preg_match - php

我有一个关于正则表达式的问题,我不明白为什么函数 returns 1 而它应该 return 0,因为字符串与正则表达式不匹配。

$t = preg_match("/DOC|doc|doc_[IVXCL]{1,6}_[A-Z]{1}_[A-Z0-9]{2,5}\.pdf/", "DOC_TRF4_DEZ_2014.pdf");

echo $t;

它 returns 正确,因为它匹配 DOC
您必须在正则表达式中对某些部分进行分组:

preg_match("/(?:DOC|doc|doc)_[IVXCL]{1,6}_[A-Z]{1}_[A-Z0-9]{2,5}\.pdf/", "DOC_TRF4_DEZ_2014.pdf");
//    here __^           __^

但是你要匹配的不是很清楚。