I have string like fd_val__pharmacy_1_2_3_text
In that above string i want replace
- double underscore with single underscore
- replace
fd_
with blank - replace
_1
,_2
,_3
with blank.
I am tried by using Replace function multiple times. But i want to do it by using regexp_replace function only once. Is it possible. Please help me with the query.
Output of the query should be val_pharmacy_text
2
Answers
To get the desired output as stated above you can use the following query to solve it.The query is as follows:
sample illustration and implementation can be found here: https://dbfiddle.uk/93OllCaa
Hope this helps
As of Postgres 16, there’s no built-in function that generically does multiple replacements in a single pass.
The Perl substitution operator provides an efficient way do it, though. I use the following
plperl
function:Example:
You may find more details on the problem statement and implementation in that blog post: Multiple strings replacement with plperl.