Bluehost.com Web Hosting $6.95

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

This is a discussion on REGEXP and MySQL Select: Retreiving What I'm Looking For? within the MySQL Database forums, part of the Database Forums category; Hi there If I have a "Filename" column in a database, and I want to grab the EXTENSION ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-03-2006
Good Man
 
Posts: n/a
Default REGEXP and MySQL Select: Retreiving What I'm Looking For?

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!!


Reply With Quote
  #2 (permalink)  
Old 11-03-2006
Radoulov, Dimitre
 
Posts: n/a
Default Re: REGEXP and MySQL Select: Retreiving What I'm Looking For?


> 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?


SELECT f.FileID,f.FileName,right(filename,instr(reverse(f ilename),'.')-1)
as FileExt
FROM ProjFiles f
WHERE f.FolderID=584


Regards
Dimitre



Reply With Quote
  #3 (permalink)  
Old 11-03-2006
Good Man
 
Posts: n/a
Default Re: REGEXP and MySQL Select: Retreiving What I'm Looking For?

"Radoulov, Dimitre" <cichomitiko@gmail.com> wrote in
news:454bc450$0$49201$14726298@news.sunsite.dk:

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

>
> SELECT
> f.FileID,f.FileName,right(filename,instr(reverse(f ilename),'.')-1) as
> FileExt FROM ProjFiles f
> WHERE f.FolderID=584
>
>
> Regards
> Dimitre



Thank you very much Dimitre!


Reply With Quote
  #4 (permalink)  
Old 11-04-2006
strawberry
 
Posts: n/a
Default Re: REGEXP and MySQL Select: Retreiving What I'm Looking For?


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

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 03:14 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0