I'd like to use some processing function instead of replacement text in regexp_replace function. Is it possible to use a function with matches as arguments, like:
SELECT REGEXP_REPLACE( description, '\[([is]?:?)(\d+)\]', some_custom_function(\1, \2), 'gi' )
FROM some_table
WHERE id = 123;
Of course, backreferences \1 and \2 do not work here, but is there some way to use variables instead of them?
Background: description may contain more than one string with a pattern like [12345] or [i:12345] or [s:12345] and I'd like to process such matches into advanced strings, so I thought the best way is to write a custom function and call it with matches of regex_replace. I just did not found in the docs, how could I use matches as variable/arguments. Is this possible or what is a better way to accomplish my goal?
Example description field:
Lorem ipsum dolor sit amet [123], consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et [234] magna aliqua.
Desired output:
Lorem ipsum dolor sit amet "one-two-three", consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et "two-three-four" magna aliqua.