# Variable regex with forward slash

**URL:** <https://community.grafana.com/t/variable-regex-with-forward-slash/75446>\
**Category:** InfluxDB\
**Tags:** influxdb\
**Created:** [November 4, 2022, 12:45pm UTC](https://community.grafana.com/t/variable-regex-with-forward-slash/75446 "2022-11-04T12:45:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rmorgan466](https://avatars.discourse-cdn.com/v4/letter/r/f14d63/32.png) [@rmorgan466](https://community.grafana.com/u/rmorgan466)\
**Post date:** [November 4, 2022, 12:45pm UTC](https://community.grafana.com/t/variable-regex-with-forward-slash/75446/1 "2022-11-04T12:45:00Z")

</div>

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

```auto
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

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

```

i keep getting invalid: compilation failed

---

<div class="post-metadata">

**Author:** ![grant2](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/grant2/32/42281_2.png) [@grant2](https://community.grafana.com/u/grant2)\
**Post date:** [November 4, 2022, 9:46pm UTC](https://community.grafana.com/t/variable-regex-with-forward-slash/75446/2 "2022-11-04T21:46:39Z")

</div>

Do any of these work?

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

```

or

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

```

or

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

```

---

<div class="post-metadata">

**Author:** ![jangaraj](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/jangaraj/32/39197_2.png) [@jangaraj](https://community.grafana.com/u/jangaraj)\
**Post date:** [November 4, 2022, 10:33pm UTC](https://community.grafana.com/t/variable-regex-with-forward-slash/75446/3 "2022-11-04T22:33:47Z")

</div>

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

> **[regexp.quoteMeta() function | Flux 0.x Documentation](https://docs.influxdata.com/flux/v0.x/stdlib/regexp/quotemeta/)**
>
> regexp.quoteMeta() escapes all regular expression metacharacters in a string.

---

<div class="post-metadata">

**Author:** ![rmorgan466](https://avatars.discourse-cdn.com/v4/letter/r/f14d63/32.png) [@rmorgan466](https://community.grafana.com/u/rmorgan466)\
**Post date:** [November 6, 2022, 12:21pm UTC](https://community.grafana.com/t/variable-regex-with-forward-slash/75446/4 "2022-11-06T12:21:11Z")

</div>

I really appreciate it. Thanks a lot

---

<div class="post-metadata">

**Author:** ![grant2](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/grant2/32/42281_2.png) [@grant2](https://community.grafana.com/u/grant2)\
**Post date:** [November 6, 2022, 12:22pm UTC](https://community.grafana.com/t/variable-regex-with-forward-slash/75446/5 "2022-11-06T12:22:29Z")

</div>

Which expression worked (if any)?

---

<div class="post-metadata">

**Author:** ![rmorgan466](https://avatars.discourse-cdn.com/v4/letter/r/f14d63/32.png) [@rmorgan466](https://community.grafana.com/u/rmorgan466)\
**Post date:** [March 29, 2023, 4:30am UTC](https://community.grafana.com/t/variable-regex-with-forward-slash/75446/6 "2023-03-29T04:30:12Z")

</div>

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

This statement worked
