# Grafana - Using a variable as regex in Prometheus query

**URL:** <https://community.grafana.com/t/grafana-using-a-variable-as-regex-in-prometheus-query/24132>\
**Category:** Prometheus\
**Created:** [December 20, 2019, 3:44pm UTC](https://community.grafana.com/t/grafana-using-a-variable-as-regex-in-prometheus-query/24132 "2019-12-20T15:44:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikedavem](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@mikedavem](https://community.grafana.com/u/mikedavem)\
**Post date:** [December 20, 2019, 3:44pm UTC](https://community.grafana.com/t/grafana-using-a-variable-as-regex-in-prometheus-query/24132/1 "2019-12-20T15:44:09Z")

</div>

Hi all,

I’m new on Grafana and I’m trying to figure out how I can use a variable regexp in a Prometheus query

My variable is about mssql instance name - **sql\_instance** in **server:instance** format

I would like to use the first part of the variable ( before : ) to be used as parameter in the following query:

`win_cpu_Percent_Processor_Time{host="sql_intance_first_part",exported_instance='_Total'}`

Can anyone put me on the right track ?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![mikedavem](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@mikedavem](https://community.grafana.com/u/mikedavem)\
**Post date:** [January 27, 2020, 2:30pm UTC](https://community.grafana.com/t/grafana-using-a-variable-as-regex-in-prometheus-query/24132/2 "2020-01-27T14:30:29Z")

</div>

Hi,

Just to update this thread, I changed finally the way to create my variable.

Instead of using directly the mssql instance name, I use both label\_replace() function and label correletion AND ON to address my need

Regards
