RE: [PHP] Reg Ex

From: Date: Fri, 31 Oct 2008 14:51:59 +0000
Subject: RE: [PHP] Reg Ex
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-282706@lists.php.net to get a copy of this message
> -----Original Message----- > From: Kyle Terry [mailto:kyle@kyleterry.com] > 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

« previous php.general (#282706) next »