| 
	
 | 
 Posted by Anthony Levensalor on 12/29/07 07:29 
Tim Roberts said: 
> My Pet Programmer <anthony@mypetprogrammer.com> wrote: 
>> preg_match('/^([a-zA-Z]\:)(\\[^\\/:*?<>"|]*(?<![  
>> ]))*(\.[a-zA-Z]{2,6})$/', $filename); 
>> 
>> That one should only match valid filenames. 
>  
> There are two things here I don't understand.  First, I don't understand 
> what you are trying to do with (?<![ ]).  (I assume there was a space in 
> there that caused the line to wrap.)  As I read it, that says "fail if the 
> last character of the previous match was a space", but since the pattern 
> before it matches all the characters in the pattern after it, I don't see 
> how it could ever take effect. 
>  
> Second, I don't get what you are trying to do with (\.[a-zA-Z]{2,6}).  Is 
> that supposed to be matching an extension?  That fails for "test.c". 
>  
> Also, that requires a drive letter.  Was that your intent? 
Actually, I made a mistake in posting that, grabbed a regExp from a  
completely different RegEx scheme. I thought you were looking for a  
windows workaround, and I completely spaced it and gave you one of their  
..NET ones. Sorry about that. 
 
This one is the one I meant to hand off. 
preg_match('![^A-Z0-9_\.]!i',$filename) 
 
If it matches, then the filename is no good, ok otherwise 
Test cases: 
 
lib.so - Ok 
tbl_status - Ok 
my file is cool.txt NOT Ok 
\ this- isn't value NOT Ok 
text.c - Ok 
foo - Ok 
superlong_with_underscores.png - Ok 
ILikeTrucks!.jpg NOT Ok 
 
REALLY sorry about the mix-up. 
 
~A! 
 
--  
Anthony Levensalor 
anthony@mypetprogrammer.com 
 
Only two things are infinite, the universe and human stupidity, 
and I'm not sure about the former. - Albert Einstein
 
  
Navigation:
[Reply to this message] 
 |