Docker Image Tag in PY
Match Docker image references with an explicit tag — e.g. nginx:1.21, mycorp/service:v2.3.1.
Try it in the PY tester →Pattern
regexPY
\b[a-z0-9]+(?:[._\-\/][a-z0-9]+)*:[\w.\-]+\b (flags: g)Python (re) code
pyPython
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+.
How the pattern works
Image name is lowercase alphanumerics with optional . _ - / separators for registry paths. Tag follows the colon and can include letters, digits, dots, hyphens, and underscores.
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