regexp_matches更好的方法来摆脱返回的大括号

Ole*_*yuk 14 postgresql

是否有一些更好的方法来修剪{""}regexp_matches的结果:

trim(trailing '"}' from trim(leading '{"' from regexp_matches(note, '[0-9a-z \r\n]+', 'i')::text))
Run Code Online (Sandbox Code Playgroud)

a_h*_*ame 27

regexp_matches()返回所有匹配的数组.数组的字符串表示包含花括号,这就是你得到它们的原因.

如果您只想要所有匹配项的列表,可以使用array_to_string()将结果转换为"简单"文本数据类型:

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

如果您只对第一个匹配感兴趣,可以选择数组的第一个元素:

(regexp_matches(note, '[0-9a-z \r\n]+', 'i'))[1]
Run Code Online (Sandbox Code Playgroud)