Re: preg help



On Thu, 13 Oct 2005 05:34:22 -0700, system7designs@xxxxxxxxx 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

.



Relevant Pages

  • preg help
    ... regular expression that will select everything BUT files/folders that ... Prev by Date: ...
    (comp.lang.php)
  • Re: help make it faster please
    ... The word_finder regular expression defines what will be considered a ... through 9, underscore}". ... Also--- It looks like I forgot to lowercase matched words. ... Prev by Date: ...
    (comp.lang.python)
  • Re: preg help
    ... > regular expression that will select everything BUT files/folders that ... Justin Koivisto, ZCE - justin@xxxxxxxxx ... Prev by Date: ...
    (comp.lang.php)
  • Re: perl script question.
    ... Time to disect a regular expression. ... after the underscore we've forced a match to. ... either zero or one of those. ... this paragraph wouldn't be deleted. ...
    (freebsd-questions)
  • Character class [W_] clarification
    ... Character Class Regex Regular Expression Regular Expressions \W_ \W ... i.e. to replace (all non-word character and underscore) with. ... That is to replace (non-word characters including underscore) with ...
    (comp.lang.perl.misc)