> -----Original Message-----
> From: Kyle Terry [mailto:[EMAIL PROTECTED]
> Sent: Friday, October 31, 2008 7:28 AM
> To: PHP General Mailing List
> Subject: [PHP] Reg Ex
> 
> I'm horrible with regular expression. I need to match the text before
a
> file
> extension. So if the file is called US.123.kyle.20081029.zip, I would
> then
> need to match US.123.kyle.20081029.

Someone suggested pathinfo() already... and brought up the issues of
extensions < 3 chars and files with no "basename" (i.e., ".htaccess")...

Checked out www.php.net/pathinfo, and ran a demo on my own machine. I
can't test the .htaccess problem, since I'm running Windows (and M$
won't let you have files that start with "."), but I tested it with
"a.b.c.d" and the extension was returned as "d". Basename was "a.b.c".

Sounds like it will do exactly what you are trying to accomplish. For
what it's worth, if I were to do it with a regular expression, I would
use:

$filename = "us.123.kyle.20081029.zip";
preg_match('/(.*)\..*$/', $filename, $match);

Check out www.regular-expressions.info ... the only excuse you can have
for not knowing is that you haven't tried to learn yet. ;)

HTH,


Todd Boyd
Web Programmer




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to