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:
Running::armada-api-5ff69858bd-npnl6
Running::cm-cert-manager-856678cfb7-fgbdb
Running::cm-cert-manager-856678cfb7-x64v2
Running::cm-cert-manager-cainjector-85849bd97-7jbws
Running::cm-cert-manager-cainjector-85849bd97-k4xtc
Running::node-exporter-844dg

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

@chembakayalabharath

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:

^\D+

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:

^\D+(?=-\d)

1 Like

Thansk for your help