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 Pattern | Name / Component | Function & Rule |
|---|---|---|
| registry/ | Optional Registry | Domain host like ghcr.io or docker.io. |
| repository | Repository path | Namespace and image name. |
| :[\w.-]{0,127} | Tag | Alphanumeric tag up to 128 characters. |
Frequently Asked Questions
Is 'latest' matched automatically if omitted?
Related Regular Expressions
Browse All 40 PatternsCode & Markup
Semantic Version (SemVer 2.0)
Full SemVer 2.0.0 specification regex validating major, minor, patch, and optional pre-release/build tags.
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/Test regex
Code & Markup
Git Commit SHA-1 & SHA-256
Matches Git commit SHA hashes: 7-character short commit IDs or 40-character full SHA-1 hashes.
/^\b([a-f0-9]{7}|[a-f0-9]{40})$/iTest regex
Code & Markup
.env Configuration Key-Value
Parses standard `.env` file entries matching uppercase snake_case keys and their string values.
/^([A-Z_][A-Z0-9_]*)=(.*)$/mTest regex