Can you extract a word from within a tag to automatically label the legend?


I have some measurements in InfluxDB that I am trying to graph with Grafana. There is a Tag called “friendly_name”, which is in the format:
friendly_name = RHT Sensor (***)
where *** can vary (i.e. Kitchen, Bedroom, etc).

I am using GROUP BY(friendly_name) in the query, which gives the following:

The problem is that I want to rename the legend entries automatically to just show the room name (i.e.Kitchen, Lounge, and Main Bedroom, in this example). How can I do this?

If I just add $tag_friendly_name to the Alias field, then it doesn’t quite work:

I want to remove the RHT Sensor (***) text, and just extract the room name.

Thank you!


Would it be easier to use an Override, like this?

Possibly - what needs to be typed in to the Display Name box?

Does it need to be some kind of regex, in order to extract the room name?


There are many options to set up the override. Have you tried working through any of these?


Yes, I tried to choose “Fields with name” set to “value”, because every single one of my data have a field called “value”, and so I chose this because I want to override the display name of all traces. Then I tried some kind of regex in the display name box, but I think I am barking up the wrong tree, and don’t really understand it… sorry, I have never used regex!

Can anyone help me solve this? Thanks!

Hi @ppxtb,
In Transform tab (near Query) you can choose Rename by regex and for Match enter:


and leave Replace as $1.

Grafana regex

Regex breakdown:

.* - means any symbol 0 or more times (basically means match anything)
\( - specifies that after anything there must be a literal symbol (
( - starts matching group
[^)]+ - means match anything until you find ) symbol
) - closes matching group
.* - matches anything till the end

Replace breakdown

$1 - means return what you matched in first group (in this example only 1 group exists)

For checking regex I suggest regex101 site because there you can see what you matched with regex (marked in colors) and explanations. Few days ago I read that Grafana uses Golang flavor of regex so be sure to click on that on left menu:


Data from your example:

/RHTsensors\.first {friendly_name: RHT Sensor (Kitchen)}
/RHTsensors\.first {friendly_name: RHT Sensor (Lounge)}
/RHTsensors\.first {friendly_name: RHT Sensor (Main Bedroom)}



Those links helped me to understand how it’s done:

Best regards,


Works like a charm! Thank you! (Great website resource as well for the Regex testing).

What is the difference between the “Transform → Rename by regex” approach vs “Override → Display Name” approach? What is the purpose of each of these?

You are welcome! :slight_smile:

The main difference is that with “Transform → Rename” you are using regex to match specific part of time series name (in your example you were matching part of friendly_name tag) for all queries (A,B,C… - you only have one) you have in panel, while in “Override → Display Name” you are using regex to match specific fields to which you will apply property override (in this case that is Display Name). Display Name option does not support regex (they would be interpreted as literal symbols as you show us on post 5).

Display name option is useful for example if you are using InfluxDB with Flux language (v 2.x) and you want to change field name to value of specific tag ( for example to change field name to value of host tag use ${} ). That would act same as ALIAS BY = $tag_host in Influx QL (v.1x)

More about display name can be found on:

Best regards,

1 Like