Skip to content

Instantly share code, notes, and snippets.

@dungdm93
Last active September 23, 2019 07:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dungdm93/b75178a526aeb346e612c51e44c8b6fa to your computer and use it in GitHub Desktop.
Save dungdm93/b75178a526aeb346e612c51e44c8b6fa to your computer and use it in GitHub Desktop.
SemVer regex

Canonical regex

/^
(?'MAJOR'
    0|(?:[1-9]\d*)
)
\.
(?'MINOR'
    0|(?:[1-9]\d*)
)
\.
(?'PATCH'
    0|(?:[1-9]\d*)
)
(?:-(?'prerelease'
    (?:0|(?:[1-9A-Za-z-][0-9A-Za-z-]*))
    (?:\.
        (?:0|(?:[1-9A-Za-z-][0-9A-Za-z-]*))
    )*
))?
(?:\+(?'build'
    (?:0|(?:[1-9A-Za-z-][0-9A-Za-z-]*))
    (?:\.
        (?:0|(?:[1-9A-Za-z-][0-9A-Za-z-]*))
    )*
))?
$/

regex101 | ref

Simple Regex used for Docker image tag

^v?(\d+)(\.\d+){0,2}(-[\w\.\+\-]+)?$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment