Skip to content

Instantly share code, notes, and snippets.

@DamienGarrido
Last active January 22, 2020 10:17
Show Gist options
  • Save DamienGarrido/acaf7cc117bbe741e0fd166eaad7338b to your computer and use it in GitHub Desktop.
Save DamienGarrido/acaf7cc117bbe741e0fd166eaad7338b to your computer and use it in GitHub Desktop.
Docker image name regular expression
#!/bin/bash
cat <<EOT | grep -nP '^(?:([a-zA-Z0-9.-]+(?:\.[a-zA-Z0-9-]+)+)(?::(\d+))?\/)?((?:[^/:\r\n]*\/)*?)([^/:\r\n]+)(?::([^/:\r\n]+))?$'
hostname.example.com:80/some/path-to/image_name-1.0:with_tag-1.0.0
hostname.example.com/some/path-to/image_name-1.0:with_tag-1.0.0
some/path-to/image_name-1.0:with_tag-1.0.0
image_name-1.0:with_tag-1.0.0
hostname.example.com:80/some/path-to/image_name-1.0
hostname.example.com/some/path-to/image_name-1.0
some/path-to/image_name-1.0
image_name-1.0
EOT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment