Docker Image TagRegex — Pattern, Examples & Code
^(?:[a-z0-9]+(?:[._\-][a-z0-9]+)*\/)?[a-z0-9]+(?:[._\-][a-z0-9]+)*(?::[a-zA-Z0-9._\-]+)?$What it matches / doesn't match
| Matches ✅ | Does not match ❌ |
|---|---|
●nginx:latest | ●UPPERCASE/image |
●my-org/api-server:1.2.3 | ●image:tag:extra |
●ubuntu:22.04 | ●image with spaces |
How it works
Matches Docker image references in name:tag format with an optional namespace prefix. Image names are lowercase alphanumeric with dots, underscores, or hyphens as separators. The tag (after :) allows alphanumeric, dots, underscores, and hyphens. Does not include registry host validation (e.g., ghcr.io/).
Code Usage
JavaScript
const regex = /^(?:[a-z0-9]+(?:[._\-][a-z0-9]+)*\/)?[a-z0-9]+(?:[._\-][a-z0-9]+)*(?::[a-zA-Z0-9._\-]+)?$/;
regex.test("nginx:latest"); // truePython
import re
pattern = re.compile(r'^(?:[a-z0-9]+(?:[._\-][a-z0-9]+)*/)?[a-z0-9]+(?:[._\-][a-z0-9]+)*(?::[a-zA-Z0-9._\-]+)?$')
bool(pattern.match("nginx:latest")) # TrueGo
import "regexp"
r := regexp.MustCompile(`^(?:[a-z0-9]+(?:[._-][a-z0-9]+)*/)?[a-z0-9]+(?:[._-][a-z0-9]+)*(?::[a-zA-Z0-9._-]+)?$`)
r.MatchString("nginx:latest") // trueNeed a custom regex for a different use case?
Generate a custom regex with AI →FAQ
What does the Docker Image Tag regex pattern match?
Matches Docker image references in name:tag format with an optional namespace prefix. Image names are lowercase alphanumeric with dots, underscores, or hyphens as separators. The tag (after :) allows alphanumeric, dots, underscores, and hyphens. Does not include registry host validation (e.g., ghcr.io/).
How do I use the Docker Image Tag regex in JavaScript?
const regex = /^(?:[a-z0-9]+(?:[._\-][a-z0-9]+)*\/)?[a-z0-9]+(?:[._\-][a-z0-9]+)*(?::[a-zA-Z0-9._\-]+)?$/; regex.test("nginx:latest"); // true
Can I use the Docker Image Tag regex in Python?
Yes. import re pattern = re.compile(r'^(?:[a-z0-9]+(?:[._\-][a-z0-9]+)*/)?[a-z0-9]+(?:[._\-][a-z0-9]+)*(?::[a-zA-Z0-9._\-]+)?$') bool(pattern.match("nginx:latest")) # True
