2

regex_matches returns a string array : {first match, second match}. How do I access the elements within it? I have tried:

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 Answer 1

6

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.