For example, i have:
string example = 'word1,word2,word3,word4,word5'
How can i convert to something like this:
string example = '[word1],[word2],[word3],[word4],[word5]'
>Solution :
We can use a combination of REPLACE() and string concatenation:
SELECT val, CONCAT('[', REPLACE(val, ',', '],[') , ']') AS output
FROM yourTable;
On MySQL 8+, we can use a regex replacement:
SELECT val, REGEXP_REPLACE(val, '([^,]+)', '[$1]') AS output
FROM yourTable;