'A regex in query in Grafana

I am a new developer in Grafana and I would like to have a query that returns a variable having "CA" at the END of its name.

I was using SEARCH key code but it seems that it returns only the contained characters while I am really interested in the location of those characters.

As an example, I wrote this query :

SELECT cmts_device SEARCH CA

And it shows me this as a result :

enter image description here

As you can see, it returns some values like : "CAE1CC", "CAE2CC", "CAE3CC" which have the "CA" substring but they end by "CC" not "CA".

How can I fix this pleaase ? Thank you for any help !



Solution 1:[1]

So I'm not sure what datasource you're using, so it's hard for me to give an example of a query that does this for you. But, you can use the regex field inside Grafana. This will work for any datasource. Here I'm using Prometheus, but again the actual query and datasource does not matter.

So for example, say I have a query returning container IDs:

non-filetered results

And I only wanted the container IDs that ended with the letter "b". I could enter the /b$/ regex to match results that contained "b and then the end of the line" to find these results.

filtered results

In your example, you would enter /CA$/.

Solution 2:[2]

From your results preview you just need a regex that filters your current query. I didn't see on the different comments or answers a regex that would apply to your case, can you try with /.*CA$/ ?

enter image description here

First comment by @Tayyab : enter image description here

On the answer by @Jacob:

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jacob Colvin
Solution 2 nandilov