Skip to content

Instantly share code, notes, and snippets.

@jhorsman
Last active March 29, 2024 05:25
Show Gist options
  • Star 62 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save jhorsman/62eeea161a13b80e39f5249281e17c39 to your computer and use it in GitHub Desktop.
Save jhorsman/62eeea161a13b80e39f5249281e17c39 to your computer and use it in GitHub Desktop.
Semantic versioning regex
@Tschebbischeff
Copy link

Tschebbischeff commented Feb 2, 2022

@mathomp4
It is impossible to create a pattern for semver strings with the glob-style pattern matching emmaviolet@github mentioned they use.
I'm sorry 😔

More detail if you want:

A semver string's major version part alone allows for a theoretically infinite string of numerical characters. Let's try to get the equivalent of the regex [0-9]* only.

* allows any string (excl. / maybe, then ** specifically would allow / inside).

It is limitable with a constant prefix, infix or suffix, but there is no way to limit the "type of character" it allows at the beginning and/ or end of the string.

Now * and ** are the only two special characters that allow to match more than one character.
There is no way to make ? or [set] match against more than one character and {a,b} (if even available here) is based on a and b being patterns. Those patterns might allow infinite strings by using * inside, but do not allow limiting the type of character for the same reason as above.

Hence, it's not possible to match "an infinite string comprised of only specific characters" in glob-style 🥲

@mathomp4
Copy link

mathomp4 commented Feb 2, 2022

@Tschebbischeff Yeah, I stared at it for a while but I figured "If I can't do an ls for that pattern, I can't do this". Oh well, at least I can block off v*...and hope no bosses want a v-tag! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment