sql - Postgresql regular expression matching function: regexp_matches -


given string want extract expression matching regexp (e.g. email) array. here actual code, using postgresql 9.4 :

select regexp_matches('user1@gml.com lorem ipsum user2@yho.com',                       '([a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4})',                       'g') 

the output 2 records:

 regexp_matches    -----------------  {user1@gml.com}  {user2@yho.com}  (2 rows) 

what want have matches in 1 array e.g.:

regexp_matches   ----------------- {user1@gml.com, user2@yho.com} (1 row) 

how achieve that?

you can unnest each result array, array_agg lot of them together.

it's bit ugly:

select array_agg(x) (     select unnest(        regexp_matches('user1@gml.com lorem ipsum user2@yho.com',                       '([a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4})',                       'g')     ) ) a(x); 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -