Given a string I want to extract all expression matching a regexp (e.g. email) as an array. Here is my actual code, using PostgreSQL 9.4 :
select regexp_matches('[email protected] lorem ipsum [email protected]',
'([a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4})',
'g')
The output is 2 records:
regexp_matches
-----------------
{[email protected]}
{[email protected]}
(2 rows)
What I want is to have all the matches in one array e.g.:
regexp_matches
-----------------
{[email protected], [email protected]}
(1 row)
How to achieve that?