# Formatting legend

**URL:** <https://community.grafana.com/t/formatting-legend/38516>\
**Category:** Prometheus\
**Tags:** templating\
**Created:** [October 27, 2020, 3:51pm UTC](https://community.grafana.com/t/formatting-legend/38516 "2020-10-27T15:51:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gsstark](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/gsstark/32/13465_2.png) [@gsstark](https://community.grafana.com/u/gsstark)\
**Post date:** [October 27, 2020, 3:51pm UTC](https://community.grafana.com/t/formatting-legend/38516/1 "2020-10-27T15:51:40Z")

</div>

We have promql expressions like this on virtually _all_ our graphs ☹

`label_replace(x, "instance", "$1", "instance", "([^.]+).*") `

We do this so we can have the hostname in the legend without the fqdn and port appearing which is entirely redundant for these metrics since they’re always coming from the same service within a cluster.

It really clutters up our promql metrics and make it a real pain to copy the metrics around. It seems like it this is really a display formatting issue and would be better handled in the legend format string, something like:

`{{instance|reReplaceAll('\..*$','')}}`

Better yet would be to be able to define this as a common expression in the dashboard config and then just use `host` as if it was a label without having to put this on every legend field.

Is anything like this possible today or is this a feature request?

---

<div class="post-metadata">

**Author:** ![gsstark](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/gsstark/32/13465_2.png) [@gsstark](https://community.grafana.com/u/gsstark)\
**Post date:** [October 28, 2020, 6:02pm UTC](https://community.grafana.com/t/formatting-legend/38516/2 "2020-10-28T18:02:45Z")

</div>

I couldn’t find this before but just now I found a ~~bug~~ PR on this topic:

> <https://github.com/grafana/grafana/pull/6627>

It was closed because of inactivity but it did have a lot of people asking for it and even the person closing it said he thought it was a good idea. I’m not clear why the PR wasn’t merged.

---

<div class="post-metadata">

**Author:** ![ivanahuckova](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/ivanahuckova/32/8541_2.png) [@ivanahuckova](https://community.grafana.com/u/ivanahuckova)\
**Post date:** [October 29, 2020, 2:10pm UTC](https://community.grafana.com/t/formatting-legend/38516/3 "2020-10-29T14:10:06Z")

</div>

@gsstark we plan to introduce a transform for regex renames. You can follow [this issue](https://github.com/grafana/grafana/issues/22360) for progress.

---

<div class="post-metadata">

**Author:** ![jenniferkrajic](https://avatars.discourse-cdn.com/v4/letter/j/96bed5/32.png) [@jenniferkrajic](https://community.grafana.com/u/jenniferkrajic)\
**Post date:** [December 4, 2020, 1:13am UTC](https://community.grafana.com/t/formatting-legend/38516/4 "2020-12-04T01:13:14Z")

</div>

> [@gsstark](#):
>
> label\_replace(x, “instance”, “$1”, “instance”, “([^.]+).\*”)

I am running into the same issue. Did you put the whole expression (label\_replace(x, “instance”, “$1”, “instance”, “([^.]+).\*”)) in the legend field? or is this used in the expression field where x is you metric query?

---

<div class="post-metadata">

**Author:** ![deeruattavar](https://avatars.discourse-cdn.com/v4/letter/d/8dc957/32.png) [@deeruattavar](https://community.grafana.com/u/deeruattavar)\
**Post date:** [December 6, 2021, 8:15am UTC](https://community.grafana.com/t/formatting-legend/38516/5 "2021-12-06T08:15:36Z")

</div>

Can anybody let me kow, How to display only pod name from Ex: ic-nginx-ingress-ingress-nginx-controller-5fcb5 replace to c-nginx-ingress-ingress-nginx-controller. Also danm-cni-gm4wl  
replace to “danm-cni”  
Do you have any idea or Reg Expr I can use to achieve this filtration from pod name
