Regex in Grafana templating help

Hello @all,

I have Grafana v 7.3.6 and i’m trying to extract some content from my data.I have created a variable called PQ.As datasource i am using Prometheus and the type of variable is Query.
My goal is to extract the value of label “label_chart”.For this purpose i am using the grafana pre-defined variable label_values.This will give me 3 results as shown below:

  • sdc-5.17.2-HF01
  • sdc-5.17.1-b03
  • sdc-5.17.2-HF04-b01

But instead of the whole string sdc-5.17.2-HF01 i want only first 4 characters after the first minus(-)
This means that i want to grep only 5.17.I tried serval regex patterns but without success.

Could you guys give me any suggestion?

1 Like

I think this sniplett should do the trick /sdc-(.{4})/.

I recommend testing the regex on this site. Rather helpful editor.



Very helpful.
I managed by my own to solve it using this one /([0-9]+(.[0-9]+))/ but yours looks more easier.Many thnx.

Your regex will work, but if the input to the regex changes, it’s less safe and you may get unexpected results. But if you have control of the input, that should not be a problem.:slight_smile:

This topic was automatically closed after 365 days. New replies are no longer allowed.