Grafana变量regex在使用MongoDB源时不返回结果

dy1byipe  于 12个月前  发布在  Go
关注(0)|答案(1)|浏览(85)

我在Grafana中从mongoDB查询创建一个变量。目前,我的查询返回一个元素数组,格式为:

name="Bob Hansen", id="8051240138eb2ea033aa21f3"
name="John Doe", id="4051240138eb2ea033aa21f3"
...

现在我尝试使用正则表达式来提取两个键/值对,如下所述:https://grafana.com/docs/grafana/v9.0/variables/filter-variables-with-regex/#filter-and-modify-using-named-text-and-value-capture-groups
我有以下regex:

/name="(?<text>[^"]+)|id="(?<value>[^"]+)/g

但是grafana一直不返回值,除非我删除正则表达式:(

cmssoen2

cmssoen21#

你不应该使用改变。
正则表达式中的修改意味着,一旦第一个分支匹配,第二部分就不检查了。
这种情况下的正确表达式为

name="(?<text>[^"]+)", id="(?<value>[^"]+)

演示here

相关问题