0.2.1 • Published 2 months ago

@stdlib/regexp-semver v0.2.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 months ago

reSemVer

NPM version Build Status Coverage Status

Regular expression to match a semantic version string.

Installation

npm install @stdlib/regexp-semver

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

Notice

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.

Community

Chat


License

See LICENSE.

Copyright

Copyright © 2016-2024. The Stdlib Authors.