REGEXP and MySQL Select: Retreiving What I"m Looking For?

REGEXP and MySQL Select: Retreiving What I"m Looking For?

am 03.11.2006 22:56:15 von Good Man

Hi there

If I have a "Filename" column in a database, and I want to grab the
EXTENSION of this filename... can I do it in a query using REGEXP or
something similar?

I've got this going:

"SELECT f.FileID,f.FileName,f.FileName REGEXP '.+\.([^.]+)$' AS FileExt
FROM ProjFiles f
WHERE f.FolderID=584"

But my resulting "FileExt" column just shows a '1' (meaning that yes, a
file extension was found).

Instead of getting a "yes/no" answer from my regexp, can I actually get
the file extension itself?

Thanks!!

Re: REGEXP and MySQL Select: Retreiving What I"m Looking For?

am 04.11.2006 00:48:54 von zac.carey

Good Man wrote:
> Hi there
>
> If I have a "Filename" column in a database, and I want to grab the
> EXTENSION of this filename... can I do it in a query using REGEXP or
> something similar?
>
> I've got this going:
>
> "SELECT f.FileID,f.FileName,f.FileName REGEXP '.+\.([^.]+)$' AS FileExt
> FROM ProjFiles f
> WHERE f.FolderID=584"
>
> But my resulting "FileExt" column just shows a '1' (meaning that yes, a
> file extension was found).
>
> Instead of getting a "yes/no" answer from my regexp, can I actually get
> the file extension itself?
>
> Thanks!!

That looks long-winded. Why not have a look at REVERSE