DevTools
Back to Regex Tester

Semantic Version (SemVer) Regex Pattern

Match semantic versioning strings (e.g., v1.2.3-beta.1+build.123) with regex. Supports pre-release and build metadata.

The Pattern

/\bv?\d+\.\d+\.\d+(?:-[\w.]+)?(?:\+[\w.]+)?\b/g

How It Works

TokenMeaning
\bWord 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)

Test Cases

v1.0.0Match
2.3.4-beta.1Match
10.20.30+build.456Match
1.2.3-alpha+001Match
1.2No match
version1No match

Code Examples

javascript
const 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"]
python
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']

Common Use Cases

Related Patterns

Want to test this pattern with your own data?

Try this pattern in Regex Tester →