You are here: Re: strpos - and multiple needles? « PHP Programming Language « IT news, forums, messages
Re: strpos - and multiple needles?

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация