I have some sample text
# HELP aaasd asdads
# TYPE ASDA dasdas
goodmetric_total{"camel-1"} 777.0
# HELP qqq www
# TYPE eee rrr
badmetric_total{"camel-1"} 888.0
I will need to get numbers from a specific string. Using String.format, I will substitute the values I need. For example goodmetric_total.
How do I write a regexp to get only a numerical value? At the moment, I have solutions for searching string first.
^goodmetric.+\d+
And already in this line look for numbers.
I think you can do all this in one operation. Thanks!
777.0or777.0and1? fromgoodmetric_total{"camel-1"} 777.0?^goodmetric.+ (\d+)(?:\.0)?$(demo) (where you capture the int part of the number into Group 1).String value=""; if (line.trim().startsWith("goodmetric_total")) { value = line.split("\\s+")[1]; }.