diff --git a/docs/querying/functions.md b/docs/querying/functions.md index 55ed92ecc..bec87a69d 100644 --- a/docs/querying/functions.md +++ b/docs/querying/functions.md @@ -419,11 +419,10 @@ label_join(up{job="api-server",src1="a",src2="b",src3="c"}, "foo", ",", "src1", ## `label_replace()` For each timeseries in `v`, `label_replace(v instant-vector, dst_label string, replacement string, src_label string, regex string)` -matches the regular expression `regex` against the value of the label `src_label`. If it +matches the [regular expression](https://github.com/google/re2/wiki/Syntax) `regex` against the value of the label `src_label`. If it matches, the value of the label `dst_label` in the returned timeseries will be the expansion of `replacement`, together with the original labels in the input. Capturing groups in the -regular expression can be referenced with `$1`, `$2`, etc. If the regular expression doesn't -match then the timeseries is returned unchanged. +regular expression can be referenced with `$1`, `$2`, etc. Named capturing groups in the regular expression can be referenced with `$name` (where `name` is the capturing group name). If the regular expression doesn't match then the timeseries is returned unchanged. `label_replace` acts on float and histogram samples in the same way. @@ -433,6 +432,11 @@ This example will return timeseries with the values `a:c` at label `service` and label_replace(up{job="api-server",service="a:c"}, "foo", "$1", "service", "(.*):.*") ``` +This second example has the same effect than the first example, and illustrates use of named capturing groups: +``` +label_replace(up{job="api-server",service="a:c"}, "foo", "$name", "service", "(?P.*):(?P.*)") +``` + ## `ln()` `ln(v instant-vector)` calculates the natural logarithm for all elements in `v`.