我在postgres中有一个场景,我需要收集多组方括号之间的所有条目.
以下示例将是我期望捕获的内容:
SELECT (regexp_matches('Hello [World] How [Are] You','\[(.*?)\]'))
但这简直就是回归
{World}
忽略第二个[Are]部分.
在常规正则表达式中,这似乎有效,所以我不确定它为什么会在这里失败.
理想情况下,我想返回结果,如csv文本字符串.
例如
World,Are
但我似乎无法找到正确的查询来做到这一点.
任何输入赞赏.谢谢.
解决方法
你必须使用’g’标志
SELECT (regexp_matches('Hello [World] How [Are] You','\[(.*?)\]','g'))
The “g” flag indicates that the regular expression should be tested against all possible matches in a string.