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]
Run Code Online (Sandbox Code Playgroud)
什么都行不通.我真的需要做一个字符串函数来替换两个大括号吗?这看起来很笨重
你必须使用额外的括号:
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)
Run Code Online (Sandbox Code Playgroud)