Semantic version regex pattern

Copy and test a JavaScript regex for semantic version strings, with examples and a one-click link to the regex tester.

Semantic version regex pattern

Validate whole value

Use anchors to check whether the complete value matches.

Regex: ^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$

Flags: -

Search in text

Find matching fragments inside a larger block of text.

Regex: \bv?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?\b

Flags: g

Examples that match

  • 1.2.3
  • v2.0.0-beta.1

Examples that do not match

  • 1.2
  • 01.2.3