Regex for Docker Image Tag
Validates Docker image references with optional registry, namespace, and tag.
Pattern
/^([a-z0-9]+([._-][a-z0-9]+)*(\/[a-z0-9]+([._-][a-z0-9]+)*)*)(:([a-zA-Z0-9][a-zA-Z0-9._-]{0,127}))?$/ Live Tester
Enter a string to test
Examples
✓ nginx:latest
✓ myregistry.io/myapp:v1.2.3
✓ library/ubuntu:22.04
✗ NGINX:latest
✗ :latest
✗ image:
Pattern Breakdown
^([a-z0-9]+([._-][a-z0-9]+)*) — image name segment (lowercase)
(\/...)* — optional additional path segments
(:([a-zA-Z0-9]...))? — optional colon + tag (up to 128 chars)
Code Snippets
Javascript
const regex = /^([a-z0-9]+([._-][a-z0-9]+)*(\/[a-z0-9]+([._-][a-z0-9]+)*)*)(:([a-zA-Z0-9][a-zA-Z0-9._-]{0,127}))?$/;
regex.test("nginx:latest"); // true Python
import re
pattern = r"^([a-z0-9]+([._-][a-z0-9]+)*(/[a-z0-9]+([._-][a-z0-9]+)*)*)(:([a-zA-Z0-9][a-zA-Z0-9._-]{0,127}))?$"
bool(re.match(pattern, "nginx:latest")) # True Php
$pattern = '/^([a-z0-9]+([._-][a-z0-9]+)*(\/[a-z0-9]+([._-][a-z0-9]+)*)*)(:([a-zA-Z0-9][a-zA-Z0-9._-]{0,127}))?$/';
preg_match($pattern, "nginx:latest"); // 1 Related Patterns
Email Address /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/ URL /^https?:\/\/(www\.)?[a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([a-zA-Z0-9()@:%_+.~#?&/=-]*)$/ Phone Number (International) /^\+?[1-9]\d{1,14}$/ Phone Number (US) /^\(?[2-9]\d{2}\)?[-.\s]?\d{3}[-.\s]?\d{4}$/ Phone Number (EU) /^\+?[1-9][0-9]{0,3}[\s.-]?\(?[0-9]{1,5}\)?[\s.-]?[0-9]{1,5}[\s.-]?[0-9]{1,5}$/ IPv4 Address /^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$/
Frequently Asked Questions
What is the regex for Docker Image Tag?▾
The regex pattern for Docker Image Tag is /^([a-z0-9]+([._-][a-z0-9]+)*(\/[a-z0-9]+([._-][a-z0-9]+)*)*)(:([a-zA-Z0-9][a-zA-Z0-9._-]{0,127}))?$/. Validates Docker image references with optional registry, namespace, and tag.
How do I use the Docker Image Tag regex in JavaScript?▾
In JavaScript you create the pattern with a regex literal or the RegExp constructor and call .test() to check a string against it. A ready-to-copy example is shown in the Code Snippets section above, alongside Python and PHP versions.
What does the Docker Image Tag pattern match?▾
It matches strings like nginx:latest; it rejects strings like NGINX:latest. See the Examples section above for the full list of matching and non-matching cases.