Return a regular expression to match a semantic version string.
APACHE-2.0 License
Regular expression to match a semantic version string.
npm install @stdlib/regexp-semver
Alternatively,
script
tag without installation and bundlers, use the ES Module available on the esm
branch (see README).deno
branch (see README for usage intructions).umd
branch (see README).The branches.md file summarizes the available branches and displays a diagram illustrating their relationships.
To view installation and usage instructions specific to each branch build, be sure to explicitly navigate to the respective README files on each branch, as linked to above.
var reSemVer = require( '@stdlib/regexp-semver' );
Returns a regular expression to match a semantic version string.
var RE_SEMVER = reSemVer();
// returns <RegExp>
var parts = RE_SEMVER.exec( '1.0.0' );
/* returns
[
'1.0.0',
'1',
'0',
'0',
undefined,
undefined,
index: 0,
input: '1.0.0',
groups: undefined
]
*/
parts = RE_SEMVER.exec( '1.0.0-alpha.1' );
/* returns
[
'1.0.0-alpha.1',
'1',
'0',
'0',
'alpha',
'1',
index: 0,
input: '1.0.0-alpha.1',
groups: undefined
]
*/
Regular expression to match a semantic version string.
var parts = reSemVer.REGEXP.exec( '0.2.3' );
/* returns
[
'0.2.3',
'0',
'2',
'3',
undefined,
undefined,
index: 0,
input: '0.2.3',
groups: undefined
]
*/
var reSemVer = require( '@stdlib/regexp-semver' );
var RE_SEMVER = reSemVer();
var version = '1.0.0';
var bool = RE_SEMVER.test( version );
// returns true
version = '1.0.0-alpha.1';
bool = RE_SEMVER.test( version );
// returns true
version = '1.0.0-alpha.1+build.1';
bool = RE_SEMVER.test( version );
// returns true
version = '1.0.0-alpha.1+build.1.2.b8f12d7';
bool = RE_SEMVER.test( version );
// returns true
version = '1.2';
bool = RE_SEMVER.test( version );
// returns false
version = '-1.2.3';
bool = RE_SEMVER.test( version );
// returns false
version = 'a.b.c';
bool = RE_SEMVER.test( version );
// returns false
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
See LICENSE.
Copyright © 2016-2024. The Stdlib Authors.