Templating regex exclude not working

I tried to exclude some hostname from the templating output.

Template query to get the hostname from InfluxDB,

As SHOW TAG VALUES doesn’t support time in WHERE clause, I tried to exclude some down hosts using template regex option.

Can you help me , how to exclude below hosts on templating regex option


Regex tried : /^(?!ansys.example.local$).*$/

You can use regex in the influxdb query as well to filter, or the regex option in grafana.

Not sure what the regex should look like.

Negative lookaheads are hard. Have you tried use the !~ operator (negative regex) in the the WHERE clause instead?

Something like: WHERE host !~ /^ansys*.example.local$/

I was just tackling this issue today.

My dashboard template variable is for a customer list from InfluxDB data source. The initial query looks like:
SHOW TAG VALUES FROM "series_name" WITH KEY = "customer"

Of course, I don’t want to look at any of my internal, test, or demo accounts, so I needed to use the regex to exclude those. I’m using the negative lookahead as daniellee mentioned, but since this is in the templating section and not the metrics, it’s a little different. My regex line has:

This is working for me at this time. I hope it helps you out.


#Exclude all until remain what you want

#Exclude + Include feature (this is the best)



Does regex supports excluding value derived from other variable ? I want something like this for Prometheus,

Var 1 : Prometheus query returns Stack1, Stack2, Stack3
Var 2 : If I select Stack1, all services of Stack1

Something like chained variable but now in templating !
Or any other way to achieve this.

This worked for me. Thanks!