regexp_matches摆脱返回花括号的更好方法 [英] regexp_matches better way to get rid of returning curly brackets

查看:1403
本文介绍了regexp_matches摆脱返回花括号的更好方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在比regexp_matches更好的修剪 {} 的方法,而不是:

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

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


推荐答案

regexp_matches( )返回所有匹配项的数组。数组的字符串表示形式包含花括号,这就是为什么要使用花括号。

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

如果只想列出所有匹配项,则可以使用 array_to_string()将结果转换为一个简单文本数据类型:

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(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]

这篇关于regexp_matches摆脱返回花括号的更好方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆