Kubernetes Pod Name (RFC 1123)
Validate Kubernetes pod names per the RFC 1123 DNS label rules — lowercase, ≤63 chars, no leading/trailing hyphen.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
const re = new RegExp("^[a-z0-9](?:[a-z0-9\\-]{0,61}[a-z0-9])?$", "");
const input = "nginx-deployment-66b6c48dd5-abcd1";
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-z0-9](?:[a-z0-9\-]{0,61}[a-z0-9])?$")
input_text = "nginx-deployment-66b6c48dd5-abcd1"
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-z0-9](?:[a-z0-9\-]{0,61}[a-z0-9])?$`)
input := `nginx-deployment-66b6c48dd5-abcd1`
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-z0-9](?:[a-z0-9\-]{0,61}[a-z0-9])?$Raw source: ^[a-z0-9](?:[a-z0-9\-]{0,61}[a-z0-9])?$
How it works
Examples
Input
nginx-deployment-66b6c48dd5-abcd1Matches
nginx-deployment-66b6c48dd5-abcd1
Input
my-appMatches
my-app
Input
MyAppNo match
—Common use cases
- •Helm chart values validation
- •Custom controller / operator input checks
- •GitOps tooling sanity rules
- •Cluster admission webhook policy
Related patterns
AWS S3 Bucket Name
IdentifiersValidate AWS S3 bucket names per the standard naming rules: 3–63 chars, lowercase, alphanumeric + dots + hyphens.
Kubernetes Label (key=value)
IdentifiersValidate Kubernetes label `key=value` pairs per the K8s naming spec.
Hostname (Single Label, RFC 1123)
NetworkingValidate a single-label hostname per RFC 1123: 1–63 chars, letters/digits/hyphens, can't start or end with hyphen.
npm Package Name
IdentifiersValidate npm package names including scoped packages (@org/package), per the npm naming spec.