Skip to main content
Code & Markup · In-Browser Regular Expression Lab

Docker Image Tag Regex — Match Registry, Repository & Tag Syntax

Validates Docker image references such as repository/image:tag or standard official tags.

Flags:
//none
Match Found
Load Sample:
Match Inspection & Details1 match
Match #1:nginx:alpine

Test Samples Verification Matrix

Expected Valid Samples (Should Match)

nginx:alpine Pass
ghcr.io/org/service:v1.2.3 Pass
node:20-slim Pass
redis:latest Pass

Expected Invalid Samples (Must Reject)

:latest Rejected (Pass)
repo:tag:extra Rejected (Pass)
-bad/name:tag Rejected (Pass)
Code Implementation Generator
// JavaScript / TypeScript (ES6+)
const 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})?$/;
const text = "nginx:alpine";

const isMatch = pattern.test(text);
console.log("Is Match:", isMatch);

if (isMatch) {
  const matches = text.match(pattern);
  console.log("Matches:", matches);
}

Regular Expression Token Breakdown

Validates Docker registry domain, namespace, repository name, and optional :tag component. Each component of the regular expression serves a distinct syntactical purpose as mapped below:

Token PatternName / ComponentFunction & Rule
registry/Optional RegistryDomain host like ghcr.io or docker.io.
repositoryRepository pathNamespace and image name.
:[\w.-]{0,127}TagAlphanumeric tag up to 128 characters.

Frequently Asked Questions

Is 'latest' matched automatically if omitted?
Docker CLI defaults to 'latest' if tag is omitted; this regex marks `:tag` optional.
Browse All 40 Patterns