100% Client-Side β’ 0 B Data Leaves Browser
validation
Docker Image Repository & Tag Name Regex
Validates complete Docker image references including optional registry domain, namespace, image name, and tag.
Regular Expression Pattern:
/^(?:(?=[^:\/]{1,253})(?!-)[a-zA-Z0-9-]{1,63}(?<!-)(?:\.(?!-)[a-zA-Z0-9-]{1,63}(?<!-))*(?::[0-9]{1,5})?\/)?(?:[a-z0-9]+(?:[._-][a-z0-9]+)*\/)*[a-z0-9]+(?:[._-][a-z0-9]+)*(?::[\w][\w.-]{0,127})?$/
Valid Match Example:
ghcr.io/org/service-app:v1.4.2
Invalid / Non-Match Example:
Invalid Image Name : With Spaces
Regex Syntax Breakdown & Explanation
- β’Matches optional registry host (e.g. registry.hub.docker.com:5000/)
- β’Matches multi-tier organization or username repositories
- β’Matches standard Docker tag with colon separator
Implementation in Popular Languages
JavaScript / TypeScript
const regex = /^(?:(?=[^:\/]{1,253})(?!-)[a-zA-Z0-9-]{1,63}(?<!-)(?:\.(?!-)[a-zA-Z0-9-]{1,63}(?<!-))*(?::[0-9]{1,5})?\/)?(?:[a-z0-9]+(?:[._-][a-z0-9]+)*\/)*[a-z0-9]+(?:[._-][a-z0-9]+)*(?::[\w][\w.-]{0,127})?$/;
const isValid = regex.test("ghcr.io/org/service-app:v1.4.2");
console.log(isValid); // truePython (re)
import re
pattern = r"^(?:(?=[^:\/]{1,253})(?!-)[a-zA-Z0-9-]{1,63}(?<!-)(?:\.(?!-)[a-zA-Z0-9-]{1,63}(?<!-))*(?::[0-9]{1,5})?\/)?(?:[a-z0-9]+(?:[._-][a-z0-9]+)*\/)*[a-z0-9]+(?:[._-][a-z0-9]+)*(?::[\w][\w.-]{0,127})?$"
match = re.match(pattern, "ghcr.io/org/service-app:v1.4.2")
print(bool(match)) # TrueGo (regexp)
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^(?:(?=[^:\/]{1,253})(?!-)[a-zA-Z0-9-]{1,63}(?<!-)(?:\.(?!-)[a-zA-Z0-9-]{1,63}(?<!-))*(?::[0-9]{1,5})?\/)?(?:[a-z0-9]+(?:[._-][a-z0-9]+)*\/)*[a-z0-9]+(?:[._-][a-z0-9]+)*(?::[\w][\w.-]{0,127})?$`)
fmt.Println(re.MatchString("ghcr.io/org/service-app:v1.4.2"))
}Frequently Asked Questions
Frequently Asked Questions
Everything you need to know regarding specifications, syntax, and security best practices.
The regular expression pattern is /^(?:(?=[^:\/]{1,253})(?!-)[a-zA-Z0-9-]{1,63}(?<!-)(?:\.(?!-)[a-zA-Z0-9-]{1,63}(?<!-))*(?::[0-9]{1,5})?\/)?(?:[a-z0-9]+(?:[._-][a-z0-9]+)*\/)*[a-z0-9]+(?:[._-][a-z0-9]+)*(?::[\w][\w.-]{0,127})?$/. Validates complete Docker image references including optional registry domain, namespace, image name, and tag.