REGEXVAULTv2.0
Dev & Systems/Docker
Verified Safe

Docker Image Full Reference Regex for JavaScript

/^(?:(?:[a-zA-Z0-9][a-zA-Z0-9\-._]*(?::[0-9]+)?)/)?(?:[a-z][a-z0-9\-._]*/)?[a-z][a-z0-9\-._]*(?::([a-zA-Z0-9][a-zA-Z0-9._\-]{0,127})|@(sha256:[a-fA-F0-9]{64}))?$/

What this pattern does

This page provides a comprehensive, battle-tested regular expression for matching docker image full reference, ported and verified for JavaScript. A rigorously tested regex reduces debugging time and protects your application from edge-case failures. The snippet below is ready to drop into your JavaScript project — whether you're validating in an Express middleware, a Next.js API route, or a client-side form.

Javascript Implementation

Javascript
// Docker Image Full Reference
// ReDoS-safe | RegexVault — Dev & Systems > Docker

const dockerImageFullReferenceRegex = /^(?:(?:[a-zA-Z0-9][a-zA-Z0-9\-._]*(?::[0-9]+)?)\/)?(?:[a-z][a-z0-9\-._]*\/)?[a-z][a-z0-9\-._]*(?::([a-zA-Z0-9][a-zA-Z0-9._\-]{0,127})|@(sha256:[a-fA-F0-9]{64}))?$/;

function validateDockerImageFullReference(input: string): boolean {
  return dockerImageFullReferenceRegex.test(input);
}

// Example
console.log(validateDockerImageFullReference("nginx")); // true

Test Cases

Matches (Valid)
Rejects (Invalid)
nginxNginx:latest
nginx:latestnginx: latest
ubuntu:22.04nginx:tag with space
library/nginx:alpineregistry/Image:tag
myregistry.com:5000/myimage:v1.0
nginx@sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4

When to use this pattern

This pattern is drawn from the Dev & Systems > Docker category and carries a ReDoS-safe certification. That matters for JavaScript developers because especially critical in long-running Node.js event loops where a ReDoS vulnerability can block the entire process. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.

Common Pitfalls

A registry hostname must contain a period or colon or be 'localhost' to distinguish it from a namespace — 'myregistry/image' is parsed as namespace/image on Docker Hub.

Technical Notes

Group 1 = tag, group 2 = digest. Docker resolves bare names like 'nginx' to 'docker.io/library/nginx:latest'. Always specify the full reference in IaC and CI/CD pipelines.

Have a pattern that belongs in the vault?

Submit it for review — community-verified patterns get credited to your GitHub handle. Free submissions join the queue. Priority review available for $15.

Submit a Pattern