Variable regex with forward slash

I have a dashboard variable called “filename”, which looks like

v1.tagValues(
  bucket: v.bucket,
  tag: "ff",
  predicate: (r) => true,
  start: -1d
)

It gives me values of the key for “ff”.
The values look like: /tmp/a/b, /sbin, /etc/cron

So my grafana query look like

filter(fn:(r) => r["ff"]=~ /^${filename:pipe}$/)

i keep getting invalid: compilation failed

Do any of these work?

|> filter(fn: (r) => r["ff"] == "${filename}")

or

|> filter(fn: (r) => r["ff"] =~ /${filename:regex}/)

or

 |> filter(fn: (r) => r["ff"] =~ /^${filename:regex}$/ )
1 Like

You need to ecape regular expression metacharacters in your variable, so valid regexp will be generated:

1 Like

I really appreciate it. Thanks a lot

Which expression worked (if any)?

This statement worked