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

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:

Regex101

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)}

Regex:

.*\(([^\)]+).*

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

Best regards,
ldrascic

2 Likes