Thanks for the reply. For now I used substr($filename,0,-4) and that worked perfectly. I need to learn reg ex badly :(. On Fri, Oct 31, 2008 at 7:51 AM, Boyd, Todd M. <tmboyd1@xxxxxxxx> wrote: > > -----Original Message----- > > From: Kyle Terry [mailto:kyle@xxxxxxxxxxxxx] > > Sent: Friday, October 31, 2008 7:28 AM > > To: PHP General Mailing List > > Subject: 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 > > > > -- Kyle Terry | www.kyleterry.com