Reputation: 2645
I need to match the following regular expression
lines...
# TYPE word expression
lines...
where expression can be only one of the following summary, counter, gauge, histogram or untyped
For example:
# HELP http_requests A summary of all the requests being made
# TYPE http_requests summary
http_request{requestMethod="GET",requestPath="/status/detailed",requestStatusCode="503"} 824
http_request{requestMethod="GET",requestPath="/status/detailed",requestStatusCode="503"} 334
I tried the following but it seems to not be working
?^{# TYPE}\s\w\s(summary|counter|gauge|histogram|untyped)$?
Any idea what I am missing?
Upvotes: 1
Views: 43
Reputation: 626691
You may use
(?m)^# TYPE +\w+ +(summary|counter|gauge|histogram|untyped)\r?$
That is what you need to match lines in a multiline string.
Details
(?m)
- multiline modifier^
- start of a line# TYPE +
- # TYPE
substring and one or more spaces\w+ +
- 1+ word chars and then 1+ spaces(summary|counter|gauge|histogram|untyped)
- one of the substrings in the alternation group\r?
- an optional CR symbol (necessary as $
does not match before this symbol in .NET regex)$
- end of a line.Upvotes: 1
Reputation: 184
Successfully tested with: # TYPE (.*)\b(summary|counter|gauge|histogram|untyped)\b\r?\n?
This works if you match against the whole example (multiple lines of text), but if you iterate through every line and match against the regex use:
^# TYPE (.*)\b(summary|counter|gauge|histogram|untyped)\b\r?\n?$
Upvotes: 0