reSemVer
Regular expression to match a semantic version string.
Usage
var reSemVer = require( '@stdlib/regexp/semver' );
reSemVer()
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
]
*/
reSemVer.REGEXP
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
]
*/
Examples
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