From a86e97a7d63c0e5635e164d3ae09e13a89f50c15 Mon Sep 17 00:00:00 2001 From: Andreas Hartmann Date: Sat, 20 Jan 2024 14:31:13 +0100 Subject: [PATCH] semver: Update FAQ entry on regular expressions with a third variant that works without non-capturing groups and is compatible with POSIX regex (i.e. for use in bash). --- semver.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/semver.md b/semver.md index 22c9573..a0888f9 100644 --- a/semver.md +++ b/semver.md @@ -336,7 +336,7 @@ name and the semantic version is "1.2.3". ### Is there a suggested regular expression (RegEx) to check a SemVer string? -There are two. One with named groups for those systems that support them +There are three. One with named groups for those systems that support them (PCRE [Perl Compatible Regular Expressions, i.e. Perl, PHP and R], Python and Go). @@ -346,7 +346,7 @@ See: ^(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)(?:-(?P(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$ ``` -And one with numbered capture groups instead (so cg1 = major, cg2 = minor, +One with numbered capture groups instead (so cg1 = major, cg2 = minor, cg3 = patch, cg4 = prerelease and cg5 = buildmetadata) that is compatible with ECMA Script (JavaScript), PCRE (Perl Compatible Regular Expressions, i.e. Perl, PHP and R), Python and Go. @@ -357,6 +357,16 @@ See: ^(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-]+)*))?$ ``` +One when non-capturing groups (beginning with `(?:`) aren't available (i.e. in +POSIX regex), which gives slightly different capture groups (cg1 = major, cg2 = +minor, cg3 = patch, cg5 = prerelease and cg10 = buildmetadata). + +See: + +``` +^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$ +``` + About -----