How to write a regex to parse Prometheus output

I want to shorten the metric name or i want to add particular part of the metric name to display it on the chart or table. I want the exact regex to extract
for ex:

in above I want to remove the number present at the end,like
if we take
a) Running::node-exporter-844dg
output: Running::node-exporter

b) Running::armada-api-5ff69858bd-npnl6
output: Running::armada-api

Thanks in advance


I want the exact regex

can you guarantee that the number section:

  1. will always begin with a number
  2. is the first time a number appears in the string?

if so you could write a regex that captures everything from the beggining of the string to the first appearance of a number:


check out your example on regex101, which I highly recommend for figuring out regular expressions:

or, to get rid of that last hyphen right before the number, you can add a lookahead assertion:


1 Like

Thansk for your help