Replace string by using Regular Expression

By parsing JSON array, you get values in brackets and double quotas and might need to make the string more human readable. Regular expression REGEXP_REPLACE can be used for it.

Input string: [“Blue”], [“Pink”], [“Black”]

Output string: Blue; Pink; Black

Action: Get rid of brackets with double quotas and replace comma by semicolon.

Code:

SELECT
 '["Blue"], ["Pink"], ["Black"]' as original_string,
 REGEXP_REPLACE(original_string, '[^A-Za-z,]', '') AS alpha_and_comma_chars_only,
 REGEXP_REPLACE(alpha_and_comma_chars_only, ',', '; ') AS replaced_comma
;

Result:

original_stringalpha_and_comma_chars_onlyreplaced_comma
[“Blue”], [“Pink”], [“Black”]Blue,Pink,BlackBlue; Pink; Black

Explanation:

Release space before single quote in Notepad++ by using Regular Expression

Find what: [ ]+’

Replace with: ‘

Search Mode: Regular expression

It means: Replace all repeating space characters adjacent to single quote by single quote.

[ ]+ =collect spaces

[ ]+’ =collect spaces adjacent to single quote

Similarly you can use ‘[ ]+ to collect spaces following single quote.