PHP : Sous-masques - Manual
▻http://php.net/manual/fr/regexp.reference.subpatterns.php
(?:(?!string).)
?: makes a subpattern
?! is a negative look-ahead.
Putting negative look-ahead before the dot causes regex engine to first find any occurrence of the negative look-ahead string, and only then, if the negative look-ahead string is not present, should an arbitrary character (due to the dot) match.
Du coup avec #spip pour trouver les fichiers mp3 dans le repertoire $repertoire
, mais pas dans un sous-repertoire XXX (ie qui ne contiennent pas /XXX/
dans le path), on peut écrire :
$u = preg_files($repertoire, "^$repertoire(?:(?!/XXX/).)+mp3$");
var_dump($u);