developers.do

SemVer Comparator

Compare, sort, and validate semantic version strings per SemVer 2.0.0 — with prerelease and build metadata support

Pairwise comparison

major 1 · minor 2 · patch 3

major 1 · minor 3 · patch 0

1.2.3<1.3.0

1.2.3 is less than 1.3.0.

Build metadata (the +... suffix) is ignored for precedence per SemVer 2.0.0 §10.

Sort a list of versions

Paste one version per line. Invalid lines are reported separately and excluded from the sorted output.

Sorted (lowest → highest precedence): 5 versions

  1. 1.1.0.0-alpha
  2. 2.1.0.0-rc.1
  3. 3.1.0.0
  4. 4.1.5.0
  5. 5.2.0.0

Guide

About this semver comparator

The SemVer comparator parses version strings according to Semantic Versioning 2.0.0 and compares them by precedence. It handles release, prerelease, and build metadata for two-version comparisons and batch sorting of version lists. All parsing and comparison run in your browser.

How to use the semver comparator

  1. 1.Enter two version strings (a leading "v" is optional) for a pairwise comparison.
  2. 2.Inspect the parsed major.minor.patch, prerelease, and build fields for each version.
  3. 3.For batch sorting, paste one version per line and review the sorted output.
  4. 4.Invalid lines are reported separately so you can fix them and re-run the sort.

Important details

Precedence follows SemVer 2.0.0 §11

Major, minor, and patch are compared numerically. A prerelease version has lower precedence than the same release. Prerelease identifiers are compared per-field: numeric identifiers are lower than alphanumeric identifiers, alphanumerics by ASCII sort, and a shorter prerelease list is lower when all shared identifiers are equal.

Build metadata is ignored for precedence

Identifiers after the plus sign — for example, 1.0.0+build.42 — are not used when comparing versions. Two versions that differ only in build metadata are considered equal for precedence purposes.

Frequently asked questions

Why does 1.0.0-alpha compare lower than 1.0.0?

Per SemVer 2.0.0, any prerelease version has lower precedence than its corresponding release. The prerelease identifier only adds qualification; it never raises precedence above the patch segment.

Is "v" required before the version number?

No. The comparator accepts an optional leading v or V, such as "v1.2.3", but the prefix is stripped before parsing — it is not part of the SemVer 2.0.0 BNF itself.

References: Semantic Versioning 2.0.0