Re: Find and replace
От | Tom Lane |
---|---|
Тема | Re: Find and replace |
Дата | |
Msg-id | 18540.1568234975@sss.pgh.pa.us обсуждение исходный текст |
Ответ на | Find and replace ("Campbell, Lance" <lance@illinois.edu>) |
Список | pgsql-sql |
"Campbell, Lance" <lance@illinois.edu> writes: > I don’t know the best way to do this. I need to do a find and replace in text fields. The value I need to find and replacemay occur more than once in each field per record. > The value I am trying to match on: > Starts with a single { . > Ends with a single } . > In between these brackets can be the characters 0-9, a-z, A-Z, hyphens and underscores. But no spaces. These characterscould be in any order. > The replacement value on a match is the same as what was found except for double {{ at the beginning and double }} at theend. Same values between the brackets as what was matched on. Sounds like a job for regular expressions. regression=# select regexp_replace('abc{foo1}def{goo_bug}a', '{([-_a-zA-Z0-9]*)}', '{{\1}}', 'g'); regexp_replace ---------------------------- abc{{foo1}}def{{goo_bug}}a (1 row) See https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-POSIX-REGEXP regards, tom lane
В списке pgsql-sql по дате отправления: