sindresorhus / semver-regex Goto Github PK
View Code? Open in Web Editor NEWRegular expression for matching semver versions
License: MIT License
Regular expression for matching semver versions
License: MIT License
'v1.0.0'.match(semverRegex())
returns ['v1.0.0']
but should be ['1.0.0']
.
node
Welcome to Node.js v12.6.0.
Type ".help" for more information.
> const semverRegex = require('semver-regex')
undefined
> semverRegex().test('1.2.3-alpha.10.beta.0+build.unicorn.rainbow')
false
> semverRegex().test('1.2.3-alpha.0')
false
> semverRegex().test('1.2.3-alpha.1')
true
while in semver package, .0
is considered correct and in npm doc we can see this usage
The regex allows leading zeroes in the major, minor and patch component of the version which is not allowed:
A normal version number MUST take the form X.Y.Z where X, Y, and Z are non-negative integers, and MUST NOT contain leading zeroes.
Just export the regex
Another thing is that there are a lot of useful regexps, but having them scattered is annoying. Wanna make an org/repo with all of them?
The official semver site has its own regex listings and tests.
The following link shows how this regex compares against the semver tests: https://regex101.com/r/3SKyp2/1
It's actually not clear if 0.0.0 is a valid version number under semver 2.0, but it seems wrong. The FAQ recommends starting development at 0.1.0, but that's not it in the spec, per se.
Hey man, I was just about to do a PR to add support for wildcard semver ranges like 1.x
and 1.0.*
, but just wondered if there was a particular reason they weren’t in already?
Hi all,
First of all, thanks for this package!
I'm using it to check the version input in a Vue.js frontend. However, when opening a page in Safari (the new Internet Explorer), a lookbehind in regex is not supported.
I'll try and change the Regex so it'll work in Safari. However, like most developers, regex is a "hocus-pocus language", especially when they're long like this one.
Any suggestions are welcome!
Hey, @sindresorhus. I know you might not support v2.0.0, but there are so many packages that are still using it: https://www.npmjs.com/package/semver-regex?activeTab=versions
2.0.0
1,955,620
Would it be possible to backport the fix for 2.x too?
Thanks!
PS. the latest
npm tag points to v3.1.3, not sure if that's intentional.
It looks to me like this library was built with Server side usage in mind.
On the client side, It throws an error SyntaxError: invalid regexp group
on Firefox, (works fine in Chrome)
The error seems to be coming from the lookbehind in the first group in the regexp (?<=^v?|\sv?)
.
Can you please add support for client side environments ?
Hi,
I'm using this plugin for e.g. detecting the current installment version of docker
. When running docker --version
, I get this:
Docker version 17.03.1-ce-rc1, build 3476dbf
It seems the part of 17.03.1
is a semantic version, but using semverRegex().exec(/*...*/)
it returns null
.
Should be above version of docker
be considered semantic? If so, it is possible to include this in the plugin?
Many thanks!
Test it against the following data set, it will pass some non-conforming strings and fail to pass some that are conforming.
1.2.3----RC-SNAPSHOT.12.9.1--.12
1.0.0+0.build.1-rc.10000aaa-kk-0.1
99999999999999999999999.999999999999999999.99999999999999999
Begin Invalid
1
1.2
1.2.3-0123
1.2.3-0123.0123
1.1.2+.123
+invalid
-invalid
-invalid+invalid
-invalid.01
alpha
alpha.beta
alpha.beta.1
alpha.1
alpha+beta
alpha_beta
alpha.
alpha..
beta
1.0.0-alpha_beta
-alpha.
1.0.0-alpha..
1.0.0-alpha..1
1.0.0-alpha...1
1.0.0-alpha....1
1.0.0-alpha.....1
1.0.0-alpha......1
1.0.0-alpha.......1
01.1.1
1.01.1
1.1.01
1.2
1.2.3.DEV
1.2-SNAPSHOT
1.2.31.2.3----RC-SNAPSHOT.12.09.1--..12+788
1.2-RC-SNAPSHOT
-1.0.3-gamma+b7718
+justmeta
9.8.7+meta+meta
9.8.7-whatever+meta+meta
99999999999999999999999.999999999999999999.99999999999999999----RC-SNAPSHOT.12.09.1--------------------------------..12
stroncium earned $70.00 by resolving this issue!
- Checkout the Issuehunt explorer to discover more funded issues.
- Need some help from other developers? Add your repositories on Issuehunt to raise funds.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.