How to call a function in regex_replace with matches?
0
votes
1
answer
285
views
I'd like to use some processing function instead of
replacement text
in regex_replace
function. Is there possible to use a function with matches as arguments, like:
SELECT REGEXP_REPLACE( description, '\[([is]?:?)(\d+)\]', CONCAT_WS(' ', \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 ` 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?
**EDIT** I show description
field before and after:
Lorem ipsum dolor sit amet , consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et magna aliqua.
should be after replacements like:
Lorem ipsum dolor sit amet "one-two-three", consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et "two-three-four" magna aliqua.
Asked by w.k
(141 rep)
Oct 13, 2020, 10:08 PM
Last activity: May 20, 2025, 05:00 AM
Last activity: May 20, 2025, 05:00 AM