Re: regexp_replace question/suggestions needed

Поиск
Список
Период
Сортировка
От Corey Huinker
Тема Re: regexp_replace question/suggestions needed
Дата
Msg-id CADkLM=cs=pasjJFT3iX_KrK4vh2TRo+W5rdSnxyCHR2vgnXU7w@mail.gmail.com
обсуждение исходный текст
Ответ на regexp_replace question/suggestions needed  (Christopher Molnar <cmolnar65@gmail.com>)
Ответы Re: regexp_replace question/suggestions needed  (Hector Vass <hector.vass@metametrics.co.uk>)
Список 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 по дате отправления:

Предыдущее
От: Christopher Molnar
Дата:
Сообщение: regexp_replace question/suggestions needed
Следующее
От: Hector Vass
Дата:
Сообщение: Re: regexp_replace question/suggestions needed