Re: Regexp_replace question / help needed

From: Nicolas Paris <niparisco(at)gmail(dot)com>
To: Christopher Molnar <cmolnar(at)ourworldservices(dot)com>
Cc: Forums postgresql <pgsql-general(at)postgresql(dot)org>
Subject: Re: Regexp_replace question / help needed
Date: 2015-12-09 22:25:24
Message-ID: CA+ssMOTq-fV1y+8hLU7hcf3btWTfryX9UeQpTLP2o-s1zqMvqQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,
I guess capture will help you look at
http://www.postgresql.org/docs/9.0/static/functions-matching.html

SELECT regexp_replace('http://test.com/test/testfile.php',
'^(.*)/(.*\.php)$', E'\\1&file=\\2', 'g')

2015-12-09 22:58 GMT+01:00 Christopher Molnar <cmolnar(at)ourworldservices(dot)com>:
> 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:
>
> http://test.com/test&file=
>
> What I am looking for is:
>
> http://test.com/test&file=testfile.php
>
> as a result.
>
> Would anyone here point me in the right direction?
>
> Thanks!
> -Chris

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jerry Sievers 2015-12-09 22:41:53 Re: Regexp_replace question / help needed
Previous Message Tom Lane 2015-12-09 22:24:00 Re: Regexp_replace question / help needed