# How do I extract a substring from a label'value using Grafana variable

**URL:** <https://community.grafana.com/t/how-do-i-extract-a-substring-from-a-labelvalue-using-grafana-variable/120830>\
**Category:** Dashboards\
**Tags:** dashboard-variables\
**Created:** [May 3, 2024, 2:22am UTC](https://community.grafana.com/t/how-do-i-extract-a-substring-from-a-labelvalue-using-grafana-variable/120830 "2024-05-03T02:22:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![edtshuma](https://avatars.discourse-cdn.com/v4/letter/e/4da419/32.png) [@edtshuma](https://community.grafana.com/u/edtshuma)\
**Post date:** [May 3, 2024, 2:22am UTC](https://community.grafana.com/t/how-do-i-extract-a-substring-from-a-labelvalue-using-grafana-variable/120830/1 "2024-05-03T02:22:20Z")

</div>

I am trying to setup a Grafana dashboard variable to filter out a substring from a label’s value. For the regex I have entered it as below;

```auto
/^.*managed-(.*?)_.*$/

```

I cant seem to find the most appropriate regex, I keep getting an error:

```auto
Error updating options ^.*managed-(.*?)_.*$ is not a valid regular expression.

```

The sample time series from Prometheus is given below:

```auto
apisix_http_status{code="200", route="orion-gen-proj_managed-abc-test-1_checkout-api"}
apisix_http_status{code="200",route="orion-gen-proj_managed-cus-test-1_registration-api"}
apisix_http_status{code="200",route="ext_new-exe-feature-branch_managed-att-new-ddr-feature-branch_39uy78f"}

```

The dashboard that for this metric requires that some filter value to be selected via a Grafana dashboard variable. For the filter values I require to grab only the following values:

1. “checkout-api”
2. “registration-api”
3. “39uy78f”

These substrings take any random value and are not necessarily the values “checkout-api” or “registration-api” or “39uy78f”.

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![rarisoft](https://avatars.discourse-cdn.com/v4/letter/r/c5a1d2/32.png) [@rarisoft](https://community.grafana.com/u/rarisoft)\
**Post date:** [November 19, 2025, 3:27pm UTC](https://community.grafana.com/t/how-do-i-extract-a-substring-from-a-labelvalue-using-grafana-variable/120830/2 "2025-11-19T15:27:28Z")

</div>

try: ^._managed-._?\_(.\*)"}$
