sql - Postgresql regex to return multiple values -
i have scenario in postgres need gather entries between multiple sets of square brackets.
the following example expect capture this:
select (regexp_matches('hello [world] how [are] you','\[(.*?)\]')) but returns
{world} ignoring second [are] section.
in regular regex seems work, i'm unsure why failing here.
ideally, return result as csv text string. e.g.
world,are but can't seem find right query this.
any input appreciated. thanks.
you have use 'g' flag
select (regexp_matches('hello [world] how [are] you','\[(.*?)\]','g')) the "g" flag indicates regular expression should tested against possible matches in string.
Comments
Post a Comment