how to add [] chars between numbers of string in postgresql

Advertisements

How can I convert the string

"post54post5 56post6"

to this string?

"post[54]post[5] [56]post[6]"

>Solution :

You could use a regex replacement here:

SELECT REGEXP_REPLACE('post54post5 56post6', '(\d+)', '[\1]', 'g');
-- post[54]post[5] [56]post[6]

Demo

Leave a ReplyCancel reply