regex_matches
returns a string array : {first match, second match
}. How do I access the elements within it? I have tried:
regex_matches返回一个字符串数组:{first match, second match}。如何访问其中的元素?我有尝试:
regex_matches('mystring', 'my string pattern')[0]
regex_matches('mystring', 'my string pattern') as url[0]
regex_matches('mystring', 'my string pattern') as url, url[0]
Nothing works. Do I really need to do a string function to replace the two braces? That seems pretty clunky
没有什么工作。我真的需要做一个字符串函数来替换两个大括号吗?这看起来很笨重
1 个解决方案
#1
3
you have to use extra parenthesis:
你必须使用额外的括号:
postgres=# select regexp_matches('123 333'::text, '\d{3}'::text, 'g');
regexp_matches
----------------
{123}
{333}
(2 rows)
postgres=# select (regexp_matches('123 333'::text, '\d{3}'::text, 'g'))[1];
regexp_matches
----------------
123
333
(2 rows)
#1
3
you have to use extra parenthesis:
你必须使用额外的括号:
postgres=# select regexp_matches('123 333'::text, '\d{3}'::text, 'g');
regexp_matches
----------------
{123}
{333}
(2 rows)
postgres=# select (regexp_matches('123 333'::text, '\d{3}'::text, 'g'))[1];
regexp_matches
----------------
123
333
(2 rows)