|
Posted by Mladen Gogala on 11/07/58 11:29
On Thu, 13 Oct 2005 05:34:22 -0700, system7designs@gmail.com wrote:
> I don't know preg's that well, can anyone tell me how to write a
> regular expression that will select everything BUT files/folders that
> begin with ._ or __?(that's period-underscore and underscore
> underscore)
This is probably what you want:
<?php
$patt='/^[^_.][^-]?/';
$str=array("._test","__test","_test","test","_",".","A");
foreach ($str as $i) {
if (preg_match($patt,$i)) {
print "Term $i matches pattern $patt\n";
} else print "Term $i doesn\'t match pattern $patt\n";
}
?>
When executed, it produces the following:
Term ._test doesn\'t match pattern /^[^_.][^-]?/
Term __test doesn\'t match pattern /^[^_.][^-]?/
Term _test doesn\'t match pattern /^[^_.][^-]?/
Term test matches pattern /^[^_.][^-]?/
Term _ doesn\'t match pattern /^[^_.][^-]?/
Term . doesn\'t match pattern /^[^_.][^-]?/
Term A matches pattern /^[^_.][^-]?/
--
http://www.mgogala.com
[Back to original message]
|