Semantic Version (SemVer)
Match semantic version strings like 1.2.3, 1.2.3-beta.1, or 1.2.3+build.42.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
const re = new RegExp("(?:0|[1-9]\\d*)\\.(?:0|[1-9]\\d*)\\.(?:0|[1-9]\\d*)(?:-[\\w.]+)?(?:\\+[\\w.]+)?", "g");
const input = "1.0.0";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
Python (re) code
import re
pattern = re.compile(r"(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[\w.]+)?(?:\+[\w.]+)?")
input_text = "1.0.0"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
Go (RE2) code
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[\w.]+)?(?:\+[\w.]+)?`)
input := `1.0.0`
for _, match := range re.FindAllString(input, -1) {
fmt.Println(match)
}
}Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.
Pattern
(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[\w.]+)?(?:\+[\w.]+)? (flags: g)Raw source: (?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[\w.]+)?(?:\+[\w.]+)?
How it works
Examples
Input
1.0.0Matches
1.0.0
Input
2.3.1-beta.1Matches
2.3.1-beta.1
Input
1.0.0+build.42Matches
1.0.0+build.42
Common use cases
- •Package version validation
- •Changelog parsing
- •Dependency version extraction
- •CI/CD pipeline version tagging
Related patterns
MongoDB ObjectId
IdentifiersMatch MongoDB ObjectId values — 24-character hexadecimal strings.
AWS ARN (Amazon Resource Name)
IdentifiersMatch AWS ARNs (Amazon Resource Names) across commercial, China, and GovCloud partitions.
AWS S3 Bucket Name
IdentifiersValidate AWS S3 bucket names per the standard naming rules: 3–63 chars, lowercase, alphanumeric + dots + hyphens.
Docker Image Tag
IdentifiersMatch Docker image references with an explicit tag — e.g. nginx:1.21, mycorp/service:v2.3.1.