# Is it possible to definie variable template with regex?

**URL:** <https://community.grafana.com/t/is-it-possible-to-definie-variable-template-with-regex/1391>\
**Category:** General\
**Created:** [June 16, 2017, 2:45pm UTC](https://community.grafana.com/t/is-it-possible-to-definie-variable-template-with-regex/1391 "2017-06-16T14:45:27Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![daniellee](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/daniellee/32/41_2.png) [@daniellee](https://community.grafana.com/u/daniellee)\
**Post date:** [June 17, 2017, 6:04pm UTC](https://community.grafana.com/t/is-it-possible-to-definie-variable-template-with-regex/1391/3 "2017-06-17T18:04:27Z")

</div>

yes, it is possible using the Regex field under Query options. The trick is to using a capturing group:

```auto
/(..).*/

```

for a query that would be something like this in your case:

```auto
SHOW TAG VALUES WITH KEY = "host"

```

This would capture the first two characters for every value and match on everything. You can be much more specific if you want to filter out values. The above regex for your host list would return: fr, us, uk

You can then use the above template variable in your query:

```auto
select * from data where host =~ /$tempvar.*/ limit 5;

```

Read more about templating with InfluxDB here: [http://docs.grafana.org/features/datasources/influxdb/#templating](http://docs.grafana.org/features/datasources/influxdb/#templating)

---

_[View the full topic](https://community.grafana.com/t/is-it-possible-to-definie-variable-template-with-regex/1391)._
