Kubernetes Label (key=value)
Validate Kubernetes label `key=value` pairs per the K8s naming spec.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
const re = new RegExp("^([a-zA-Z0-9](?:[\\w.\\-]{0,61}[a-zA-Z0-9])?)=([a-zA-Z0-9](?:[\\w.\\-]{0,61}[a-zA-Z0-9])?)?$", "");
const input = "app=myapp";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
Python (re) code
import re
pattern = re.compile(r"^([a-zA-Z0-9](?:[\w.\-]{0,61}[a-zA-Z0-9])?)=([a-zA-Z0-9](?:[\w.\-]{0,61}[a-zA-Z0-9])?)?$")
input_text = "app=myapp"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
Go (RE2) code
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^([a-zA-Z0-9](?:[\w.\-]{0,61}[a-zA-Z0-9])?)=([a-zA-Z0-9](?:[\w.\-]{0,61}[a-zA-Z0-9])?)?$`)
input := `app=myapp`
for _, match := range re.FindAllString(input, -1) {
fmt.Println(match)
}
}Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.
Pattern
^([a-zA-Z0-9](?:[\w.\-]{0,61}[a-zA-Z0-9])?)=([a-zA-Z0-9](?:[\w.\-]{0,61}[a-zA-Z0-9])?)?$Raw source: ^([a-zA-Z0-9](?:[\w.\-]{0,61}[a-zA-Z0-9])?)=([a-zA-Z0-9](?:[\w.\-]{0,61}[a-zA-Z0-9])?)?$
How it works
Examples
Input
app=myappMatches
app=myapp
Input
version=v1.2.3Matches
version=v1.2.3
Input
-bad=valueNo match
—Common use cases
- •kubectl label / annotation linting
- •Helm chart values validation
- •GitOps tooling (ArgoCD, Flux) policy checks
- •Cluster admission webhook input validation
Related patterns
Kubernetes Pod Name (RFC 1123)
IdentifiersValidate Kubernetes pod names per the RFC 1123 DNS label rules — lowercase, ≤63 chars, no leading/trailing hyphen.
npm Package Name
IdentifiersValidate npm package names including scoped packages (@org/package), per the npm naming spec.
AWS S3 Bucket Name
IdentifiersValidate AWS S3 bucket names per the standard naming rules: 3–63 chars, lowercase, alphanumeric + dots + hyphens.
Python Package Name (PEP 508)
IdentifiersValidate Python distribution package names per PEP 508: letters, digits, dots, underscores, hyphens.