Search Postgresql Archives

Re: Regexp_replace question / help needed

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Christopher Molnar <cmolnar@xxxxxxxxxxxxxxxxxxxx> writes:
> 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=')

There's more than one way to do it.  You could use capturing parens:

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

or you could use a lookahead constraint:

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

			regards, tom lane


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux