Match semantic versioning strings (e.g., v1.2.3-beta.1+build.123) with regex. Supports pre-release and build metadata.
/\bv?\d+\.\d+\.\d+(?:-[\w.]+)?(?:\+[\w.]+)?\b/g| Token | Meaning |
|---|---|
\b | Word boundary |
v? | Optional "v" prefix |
\d+ | Major version (one or more digits) |
\. | Literal dot separator |
\d+ | Minor version (one or more digits) |
\. | Literal dot separator |
\d+ | Patch version (one or more digits) |
(?:-[\w.]+)? | Optional pre-release label (e.g., -beta.1) |
(?:\+[\w.]+)? | Optional build metadata (e.g., +build.123) |
v1.0.0Match2.3.4-beta.1Match10.20.30+build.456Match1.2.3-alpha+001Match1.2No matchversion1No matchconst semverRegex = /\bv?\d+\.\d+\.\d+(?:-[\w.]+)?(?:\+[\w.]+)?\b/g;
const text = "Versions: v1.0.0, 2.3.4-beta.1, 10.20.30+build.456";
const matches = text.match(semverRegex);
console.log(matches); // ["v1.0.0", "2.3.4-beta.1", "10.20.30+build.456"]import re
semver_regex = r'\bv?\d+\.\d+\.\d+(?:-[\w.]+)?(?:\+[\w.]+)?\b'
text = "Versions: v1.0.0, 2.3.4-beta.1, 10.20.30+build.456"
matches = re.findall(semver_regex, text)
print(matches) # ['v1.0.0', '2.3.4-beta.1', '10.20.30+build.456']Want to test this pattern with your own data?
Try this pattern in Regex Tester →