| От | Tom Lane |
|---|---|
| Тема | Re: Regexp_replace question / help needed |
| Дата | |
| Msg-id | 12631.1449699840@sss.pgh.pa.us обсуждение исходный текст |
| Ответ на | Regexp_replace question / help needed (Christopher Molnar <cmolnar@ourworldservices.com>) |
| Список | pgsql-general |
Christopher Molnar <cmolnar@ourworldservices.com> 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
В списке pgsql-general по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера