2011-03-15 75 views
0

E.g:文件夹名称的命名模式:正则表达式进行文件夹的特殊名称模式在PHP

开头一个字母和三个或十号结束。

F3445656 
A543545 
F454534535 

我的正则表达式为:

$path = realpath('k:\\folder\\'); 

$folders = new DirectoryIterator($path); 
foreach($folders as $folder){ 
    if($folder->isDot()) continue; 
    if ($folder->isDir() && preg_match('/[A-Z][0-9]{1,9}$/', $folders)){ 
     echo $folder; 
    } 

那么,是不是做正确的方式?

非常感谢!

+0

我想你的意思'[0-9] {3,10}'? – Kobi 2011-03-15 05:59:56

回答

0

使用本

preg_match('/^[A-Z]{1}[0-9]{3,9}$/i', $folders))