# semver-regex

> Regular expression for matching semver versions

Latest version **4.0.5** (published 2022-06-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install semver-regex
pnpm add semver-regex
yarn add semver-regex
bun add semver-regex
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 4.0.5 |
| Published | 2022-06-08 |
| First published | 2014-06-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=12 |
| Dependencies | 0 |
| Unpacked size | 4.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 143 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | semver, version, versions, regex, regexp, match, matching, semantic |

## Links

- npm: https://www.npmjs.com/package/semver-regex
- Repository: https://github.com/sindresorhus/semver-regex
- Homepage: https://github.com/sindresorhus/semver-regex#readme
- Issues: https://github.com/sindresorhus/semver-regex/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/semver-regex

## Recent versions

- 4.0.5 (latest) — 2022-06-08
- 3.1.4 (version-3.1.3) — 2022-05-13
- 4.0.4 — 2022-06-05
- 4.0.3 — 2022-05-13
- 4.0.2 — 2021-10-03
- 3.1.3 — 2021-09-11
- 4.0.1 — 2021-09-11
- 4.0.0 — 2021-04-28
- 3.1.2 — 2020-12-25
- 3.1.1 — 2020-01-25
- 3.1.0 — 2019-04-30
- 3.0.0 — 2019-04-19
- 2.0.0 — 2018-03-23
- 1.0.0 — 2014-08-13
- 0.1.1 — 2014-07-20
- … 1 more at https://npm.io/package/semver-regex/versions

## README

# semver-regex

> Regular expression for matching [semver](https://github.com/npm/node-semver) versions

## Install

```sh
npm install semver-regex
```

## Usage

```js
import semverRegex from 'semver-regex';

semverRegex().test('v1.0.0');
//=> true

semverRegex().test('1.2.3-alpha.10.beta.0+build.unicorn.rainbow');
//=> true

semverRegex().exec('unicorn 1.0.0 rainbow')[0];
//=> '1.0.0'

'unicorn 1.0.0 and rainbow 2.1.3'.match(semverRegex());
//=> ['1.0.0', '2.1.3']
```

## Important

If you run the regex against untrusted user input, it's recommended to truncate the string to a sensible length (for example, 50). And if you use this in a server context, you should also [give it a timeout](https://github.com/sindresorhus/super-regex).

**I do not consider ReDoS a valid vulnerability for this package. It's simply not possible to make it fully ReDoS safe. It's up to the user to set a timeout for the regex if they accept untrusted user input.** However, I'm happy to accept pull requests to improve the regex.

## Related

- [find-versions](https://github.com/sindresorhus/find-versions) - Find semver versions in a string
- [latest-semver](https://github.com/sindresorhus/latest-semver) - Get the latest stable semver version from an array of versions
- [to-semver](https://github.com/sindresorhus/to-semver) - Get an array of valid, sorted, and cleaned semver versions from an array of strings
- [semver-diff](https://github.com/sindresorhus/semver-diff) - Get the diff type of two semver versions: `0.0.1` `0.0.2` → `patch`
- [semver-truncate](https://github.com/sindresorhus/semver-truncate) - Truncate a semver version: `1.2.3` → `1.2.0`

---
_Source: https://npm.io/package/semver-regex · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
