Re: regexp_replace question/suggestions needed - Mailing list pgsql-sql

From Corey Huinker
Subject Re: regexp_replace question/suggestions needed
Date
Msg-id CADkLM=cs=pasjJFT3iX_KrK4vh2TRo+W5rdSnxyCHR2vgnXU7w@mail.gmail.com
Whole thread Raw
In response to regexp_replace question/suggestions needed  (Christopher Molnar <cmolnar65@gmail.com>)
Responses Re: regexp_replace question/suggestions needed
List pgsql-sql


On Wed, Dec 9, 2015 at 4:57 PM, Christopher Molnar <cmolnar65@gmail.com> wrote:
Hello,

I am running into a problem and need some pointers on regexp_replace - I can't seem to find an answer in any of the online resources.

I have a string (like 40,000 with different length and number of components) of them in a field named "externalurl". I need to replace the final "/" of the string with "&file=" while preserving the filename and extension following the "/".

The closest I can get is:

regexp_replace('http://test.com/test/testfile.php','/[^/]*$','&file=') 

however this looses the file name and returns:


What I am looking for is:


as a result.

Would anyone here point me in the right direction?

Thanks!
-Chris


Not the most elegant, but this seems to do the trick

# select regexp_replace('http://test.com/test/testfile.php','/[^/]*$','') || '&file=' || regexp_replace('http://test.com/test/testfile.php','.*/','') ;
                ?column?
----------------------------------------
(1 row)



pgsql-sql by date:

Previous
From: Christopher Molnar
Date:
Subject: regexp_replace question/suggestions needed
Next
From: Hector Vass
Date:
Subject: Re: regexp_replace question/suggestions needed