Test Prometheus label matching regex. Validate Alertmanager routes and PromQL selectors. Supports RE2 syntax.
Prometheus uses RE2, which does not support backreferences or lookaround assertions.
\1) or lookaround assertions. This tester uses JS regex as an approximation but warns about lookarounds.Prometheus and Alertmanager use the RE2 regular expression engine (from Google). It is designed to be linear time, meaning it deliberately avoids features like backreferences and lookaroound that can cause catastrophic backtracking.
^ and end $. Our input field shows these anchors to remind you..*: Match anything (greedy).error|fail: Alternation (OR).[a-z0-9]+: Alphanumeric characters.node_.+: Metric names starting with "node_".Examples of using Regex in the Prometheus ecosystem.
Select time series based on regex matches (=~) or non-matches (!~):
# Select all metrics where 'job' starts with 'kube'
up{job=~"kube.*"}
# Select all requests with status string 4xx or 5xx
http_requests_total{status=~"4..|5.."}Route alerts based on labels in alertmanager.yml:
route:
receiver: 'default-receiver'
routes:
- match_re:
service: ^(foo|bar)$
receiver: 'service-owners'Prometheus is written in Go. Here is how you use the same regex engine:
package main
import (
"fmt"
"regexp"
)
func main() {
// RE2 does not support lookarounds
re := regexp.MustCompile(`^kube_.*_error$`)
fmt.Println(re.MatchString("kube_pod_container_status_waiting_reason")) // false
fmt.Println(re.MatchString("kube_pod_status_phase_error")) // true
}