# Influxql where regular expression

**URL:** https://community.influxdata.com/t/influxql-where-regular-expression/4695
**Category:** Systems
**Created:** [April 10, 2018, 8:51am UTC](https://community.influxdata.com/t/influxql-where-regular-expression/4695 "2018-04-10T08:51:21Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![merturl](https://avatars.discourse-cdn.com/v4/letter/m/7cd45c/32.png) [@merturl](https://community.influxdata.com/u/merturl)
#### Post date: [April 10, 2018, 8:51am UTC](https://community.influxdata.com/t/influxql-where-regular-expression/4695/1 "2018-04-10T08:51:22Z")

</div>

Helllo!  
i want use regular expression in “WHERE clause TAG KEY” for example  
`SELECT * FROM measurement WHERE /^(tagkey1|tagkey2|tagkey3|tagkey4|tagkey5)$/ =~ /^(1|2|3|4|5)$/ limit 1`  
it is possible?

---

<div class="post-metadata">

### Author: ![philb](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/philb/32/1805_2.png) [@philb](https://community.influxdata.com/u/philb)
#### Post date: [April 10, 2018, 4:12pm UTC](https://community.influxdata.com/t/influxql-where-regular-expression/4695/2 "2018-04-10T16:12:25Z")

</div>

Yeah you can

> **[Data Exploration | InfluxData Documentation](https://archive.docs.influxdata.com/influxdb/v1.2/query_language/data_exploration/)**

Just be careful if you have high cardinality, regex might not be too performant. I used something similar to omit irrellavent disk drives from the query.

You can also set up a template variable in grafana and use something like

SHOW TAG VALUES WITH KEY = “host” - which will show you all the hosts in the datasource. you can use it in the grafana dashboard queries also to visualise the data if you wanted. Then you can update/refresh them without editing the queries each time.

In short, yes regex works in queries. Hope it helps

---

<div class="post-metadata">

### Author: ![merturl](https://avatars.discourse-cdn.com/v4/letter/m/7cd45c/32.png) [@merturl](https://community.influxdata.com/u/merturl)
#### Post date: [April 11, 2018, 12:14am UTC](https://community.influxdata.com/t/influxql-where-regular-expression/4695/3 "2018-04-11T00:14:11Z")

</div>

thank you for reply!  
i using variable in grafana it is used by some customer, so i have to setting variable for make they do not have to modify metric because they don’t know query,  
so i use Variable it is working but Variable(turn on Multy-value option) is not working in "left Value of “Where-Clause” like that img  
 ![image](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/f/fb60fae36e124a0588959a233eda05f256372d04.png)  
influx cli print error like this

 ![image](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/7/7b46572980bacbfd91529c281e1e6c0cc0c7342e.png)

so i wonder regex not working LeftValue of Where-Clause in influxdb  
if it is not working, i try another way

(ps. i try adc hoc filter in grafana it is good but adc hoc filter not supported change databases or measurement)

---

<div class="post-metadata">

### Author: ![philb](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/philb/32/1805_2.png) [@philb](https://community.influxdata.com/u/philb)
#### Post date: [April 12, 2018, 4:10pm UTC](https://community.influxdata.com/t/influxql-where-regular-expression/4695/4 "2018-04-12T16:10:26Z")

</div>

Hi,

I believe example 4,5,6,7 on the documentation should help. [Data Exploration | InfluxData Documentation Archive](https://docs.influxdata.com/influxdb/v1.2/query_language/data_exploration/#regular-expressions)

At a guess though, counting the characters in the query it looks like it might be the ‘=’ in your query. Try changing it from

_where /PM/ = ‘1’_

to this: where /PM/ =~ ‘1’

It could be that you need to pass the regex equivillent of ‘equals to’ or ‘not equals to’ into the query.

Let me know if that works, if not i have a script somewhere that uses regex to omit specific hard drives from my alerts. I’ll try and find it.

---

<div class="post-metadata">

### Author: ![merturl](https://avatars.discourse-cdn.com/v4/letter/m/7cd45c/32.png) [@merturl](https://community.influxdata.com/u/merturl)
#### Post date: [April 13, 2018, 3:44am UTC](https://community.influxdata.com/t/influxql-where-regular-expression/4695/5 "2018-04-13T03:44:22Z")

</div>

thank you!  
I tried it on. but still not solve my problem  
this is my error in \_internalDB

 ![image](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/5/50c0c3ae854dfe8669a3244ef6abcf89079c5e71.png)

---

<div class="post-metadata">

### Author: ![philb](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/philb/32/1805_2.png) [@philb](https://community.influxdata.com/u/philb)
#### Post date: [April 13, 2018, 1:12pm UTC](https://community.influxdata.com/t/influxql-where-regular-expression/4695/6 "2018-04-13T13:12:08Z")

</div>

HI,

I don’t think that will work in the CLI. Perhaps Grafana.

If you queried select \* from cq where “query” =~ /1/ that would work, if “query” was a field or tag. I’m guessing you are trying to use /query/ to bring results based on queryFail and queryOk. where the result is greater than 0? I’m not sure that will work so i don’t know what else to suggest. I tried your query and escaping the slashes but it doesn’t like that.

A query like this will work  
select \* from cq where “hostname” =~ /Influx/

That would bring any results back from cq where the host name matched all or part. As for regexing the tags/fields like that i don’t know if you can. I can’t find anyting in the documentation to suggest otherwise.

Sorry!

---

<div class="post-metadata">

### Author: ![merturl](https://avatars.discourse-cdn.com/v4/letter/m/7cd45c/32.png) [@merturl](https://community.influxdata.com/u/merturl)
#### Post date: [April 16, 2018, 4:42am UTC](https://community.influxdata.com/t/influxql-where-regular-expression/4695/7 "2018-04-16T04:42:40Z")

</div>

I 'll find another way. Thank you for helping me !
