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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13287274/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 00:32:19  来源:igfitidea点击:

regexp_matches better way to get rid of returning curly brackets

postgresql

提问by Oleg Tsymbalyuk

Is there some better way to trim {""}in result of regexp_matches than:

有没有比以下更好的方法来修剪{""}regexp_matches 的结果:

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

回答by a_horse_with_no_name

regexp_matches()returns an array of all matches. The string representation of an array contains the curly braces that's why you get them.

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

If you just want a list of all matched items, you can use array_to_string()to convert the result into a "simple" text data type:

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

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]