Regexp_matches best way to get rid of returning curly braces

Is there a better way to trim {""} as a result of regexp_matches than:

 trim(trailing '"}' from trim(leading '{"' from regexp_matches(note, '[0-9a-z \r\n]+', 'i')::text)) 
+8
postgresql
source share
1 answer

regexp_matches() returns an array of all matches. The string representation of the array contains curly braces because of which you get them.

If you only need a list of matching elements, you can use array_to_string() to convert the result to a "simple" text data type:

 array_to_string(regexp_matches(note, '[0-9a-z \r\n]+', 'i'), ';') 

If you are only interested in the first match, you can select the first element of the array:

 (regexp_matches(note, '[0-9a-z \r\n]+', 'i'))[1] 
+19
source share

All Articles