Skip to content

Instantly share code, notes, and snippets.

@Skarlso
Last active July 17, 2020 19:34
Show Gist options
  • Save Skarlso/7d71552d88e50aba46988b0c216d26b1 to your computer and use it in GitHub Desktop.
Save Skarlso/7d71552d88e50aba46988b0c216d26b1 to your computer and use it in GitHub Desktop.
A convenient, succinct regex to verify validity of docker image tags without lookahead or lookbehind
// Deals with the following formats:
// image/tag:v1.0.0
// 123.123.123.123:123/image/tag:v1.0.0
// your-domain.com/image/tag
// your-domain.com/image/tag:v1.1.1-patch1
// image/tag
// image
// image:v1.1.1-patch
// ubuntu@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2
// etc...
package main
const dockerImageVerify = "^(([a-z0-9]|[a-z0-9][a-z0-9\\-]*[a-z0-9])\\.)*([a-z0-9]|[a-z0-9][a-z0-9\\-]*[a-z0-9])(:[0-9]+\\/)?(?:[0-9a-z-]+[/@])(?:([0-9a-z-]+))[/@]?(?:([0-9a-z-]+))?(?::[a-z0-9\\.-]+)?$"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment