473,320 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

preg help

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)

Oct 13 '05 #1
4 1960
sy************@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)


if(!preg_match('`^(\._|__)`',$filename)){
// filename does not start with "._" or "__"
}

You don't need regular expressions for this, as you could do something like:

$s=substr($filename,0,2);
if($s!='._' && $s!='__'){
// filename does not start with "._" or "__"
}

--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com
Oct 13 '05 #2
True, but I am using a function that processes zip files and it can
take a regular expression as an argument. So in this case I am limited
to a reg expression

Oct 13 '05 #3
sy************@gmail.com wrote:
True, but I am using a function that processes zip files and it can
take a regular expression as an argument. So in this case I am limited
to a reg expression


So do you need a negative look-ahead expression, or will the one I
posted earlier fit your need?

--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com
Oct 13 '05 #4
On Thu, 13 Oct 2005 05:34:22 -0700, sy************@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

Oct 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: sinister | last post by:
The examples in the online manual all seem to use double quotes, e.g. at http://us3.php.net/preg_replace Why? (The behavior is different with single quotes, and presumably simpler to...
2
by: toedipper | last post by:
Hello, The following bit of code does a preg match and does something if true (sets $browser to ppcie) Without using if then and else's how do I code it so it does not equal what it is...
14
by: frizzle | last post by:
Hi group, I have a function which validates a string using preg match. A part looks like if( !preg_match( '/^(+((*)?)?)$/', $string ) || preg_match( '/(--|__)+/' ,$string) ) { i wonder...
1
by: terence.parker | last post by:
I am trying to do a search through some data, more specifically HTML, to extract data from it. So for example I may have: <b>Title:</b<em>This is a title</em> <b>Name:</b<em>Fred</em> I wish...
5
by: monomaniac21 | last post by:
hi all what is the preg for capitals in a word to be replaced by that word preceded by a space? i need to be able to do this in preg: thisWord := this Word AnotherExample := Another Example
3
moishy
by: moishy | last post by:
If I wanted to match for instance, all characters that are not in <TAGS>, I would search for all ">ANYTHING<". But how do I make that "ANYTHING"? What will be the PREG for absolutely ANY...
1
by: maheswaran | last post by:
Want to replace the field D:\\Program Files\\xampp\\htdocs\\sample into D:\Program Files\xampp\htdocs\sample I tryed lot using ereg/preg replace but not suceed.....
2
by: JanDoggen | last post by:
function vldLicense($lic) { echo "called with lic: ". $lic . "<br>"; echo preg_match('', $lic) . "<br>"; if (preg_match('{4}-{4}-{4}-{4}', $lic) == 0) return false; return true; } gives me:
4
imarkdesigns
by: imarkdesigns | last post by:
Good day to all masters here.. good to be back here again and nice site! ok, i have a problem and still confusing to accomplish using 2 values in preg match. here is my sample code... <?php ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.