Re: Reg Ex
| From: | Kyle Terry | Date: | Fri, 31 Oct 2008 14:53:59 +0000 |
| Subject: | Re: Reg Ex | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-282707@lists.php.net to get a copy of this message | ||
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@ccis.edu> wrote:
> > -----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
>
>
>
>
--
Kyle Terry | www.kyleterry.com