Docker Image Tag
Match Docker image references with an explicit tag — e.g. nginx:1.21, mycorp/service:v2.3.1.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
const re = new RegExp("\\b[a-z0-9]+(?:[._\\-\\/][a-z0-9]+)*:[\\w.\\-]+\\b", "g");
const input = "FROM nginx:1.21";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
Python (re) code
import re
pattern = re.compile(r"\b[a-z0-9]+(?:[._\-\/][a-z0-9]+)*:[\w.\-]+\b")
input_text = "FROM nginx:1.21"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
Go (RE2) code
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`\b[a-z0-9]+(?:[._\-\/][a-z0-9]+)*:[\w.\-]+\b`)
input := `FROM nginx:1.21`
for _, match := range re.FindAllString(input, -1) {
fmt.Println(match)
}
}Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.
Pattern
\b[a-z0-9]+(?:[._\-\/][a-z0-9]+)*:[\w.\-]+\b (flags: g)Raw source: \b[a-z0-9]+(?:[._\-\/][a-z0-9]+)*:[\w.\-]+\b
How it works
Examples
Input
FROM nginx:1.21Matches
nginx:1.21
Input
image: mycorp/service:v2.3.1Matches
mycorp/service:v2.3.1
Input
ubuntu:latestMatches
ubuntu:latest
Common use cases
- •Dockerfile auditing
- •CI pipeline image pinning
- •Vulnerability scanning input
- •Deployment manifest validation
Related patterns
AWS ARN (Amazon Resource Name)
IdentifiersMatch AWS ARNs (Amazon Resource Names) across commercial, China, and GovCloud partitions.
AWS S3 Bucket Name
IdentifiersValidate AWS S3 bucket names per the standard naming rules: 3–63 chars, lowercase, alphanumeric + dots + hyphens.
Git Commit SHA
IdentifiersMatch Git commit hashes, both short (7 chars) and full (40 chars) forms.
Git Remote URL (HTTPS or SSH)
IdentifiersMatch git remote URLs in both `git@host:org/repo` and `https://host/org/repo` forms.