Code & Markup · In-Browser Regular Expression Lab
Semantic Version Regex — Match MAJOR.MINOR.PATCH with Pre-release
Full SemVer 2.0.0 specification regex validating major, minor, patch, and optional pre-release/build tags.
Flags:
//none
Match Found
Load Sample:
Match Inspection & Details1 match
Match #1:1.0.0
Test Samples Verification Matrix
Expected Valid Samples (Should Match)
1.0.0 Pass
2.14.3-beta.1 Pass
0.4.0+build.1882 Pass
3.0.0-rc.2+sha.5114f85 Pass
Expected Invalid Samples (Must Reject)
1.0 Rejected (Pass)
01.2.3 Rejected (Pass)
v1.0.0 Rejected (Pass)
1.2.3.4 Rejected (Pass)
Code Implementation Generator
// JavaScript / TypeScript (ES6+)
const pattern = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
const text = "1.0.0";
const isMatch = pattern.test(text);
console.log("Is Match:", isMatch);
if (isMatch) {
const matches = text.match(pattern);
console.log("Matches:", matches);
}Regular Expression Token Breakdown
Checks 3 non-negative integer numbers without leading zeros, plus optional pre-release and build metadata. Each component of the regular expression serves a distinct syntactical purpose as mapped below:
| Token Pattern | Name / Component | Function & Rule |
|---|---|---|
| (0|[1-9]\d*) | Major version | Non-negative integer without leading zeroes. |
| \.(0|[1-9]\d*) | Minor version | Minor number component. |
| \.(0|[1-9]\d*) | Patch version | Patch number component. |
| (?:-... | Pre-release | Optional hyphen-separated tags like -alpha.1 or -beta. |
| (?:\+... | Build metadata | Optional plus-separated build hashes. |
Frequently Asked Questions
How to permit leading 'v'?
Related Regular Expressions
Browse All 40 PatternsCode & Markup
Docker Image Name & Tag
Validates Docker image references such as repository/image:tag or standard official tags.
/^(?:(?=[^:\/]{1,253})(?!-)[a-zA-Z0-9-]{1,63}(?<!-)(?:\.(?!-)[a-zA-Z0-9-]{1,63}(?<!-))*(?::[0-9]{1,5})?\/)?(?:[a-z0-9]+(?:(?:(?:[._]|__|[-]*)[a-z0-9]+)+)?\/)*[a-z0-9]+(?:(?:(?:[._]|__|[-]*)[a-z0-9]+)+)?(?::[\w][\w.-]{0,127})?$/Test regex
Code & Markup
Git Commit SHA-1 & SHA-256
Matches Git commit SHA hashes: 7-character short commit IDs or 40-character full SHA-1 hashes.
/^\b([a-f0-9]{7}|[a-f0-9]{40})$/iTest regex
Data & Formatting
URL Slug Matcher
Matches lowercase alphanumeric strings separated by single hyphens, ideal for SEO permalinks.
/^[a-z0-9]+(?:-[a-z0-9]+)*$/Test regex