# doi-regex

> Regular expression for matching DOIs

Latest version **0.1.17** (published 2024-06-14) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.17 |
| Published | 2024-06-14 |
| First published | 2014-12-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/doi-regex) |
| Module format | CommonJS |
| Node | >=0.10.0 |
| Dependencies | 0 |
| Unpacked size | 13.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 31 |
| Author | Richard Littauer |
| Maintainers | richardlitt |
| Keywords | doi, beagle, regex, regexp, re, match, test, find, pattern, doi, digital object identifier, validate |

## Links

- npm: https://www.npmjs.com/package/doi-regex
- Repository: https://github.com/regexhq/doi-regex
- Issues: https://github.com/regexhq/doi-regex/issues
- npm.io page: https://npm.io/package/doi-regex

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 0.1.17 (latest) — 2024-06-14
- 0.1.16 — 2024-06-14
- 0.1.14 — 2024-05-15
- 0.1.13 — 2022-06-08
- 0.1.12 — 2022-03-21
- 0.1.11 — 2022-01-06
- 0.1.10 — 2018-07-17
- 0.1.9 — 2018-05-30
- 0.1.8 — 2018-05-30
- 0.1.7 — 2018-05-30
- 0.1.6 — 2018-05-30
- 0.1.5 — 2018-05-30
- 0.1.4 — 2015-10-02
- 0.1.3 — 2015-03-08
- 0.1.2 — 2014-12-19
- … 9 more at https://npm.io/package/doi-regex/versions

## README

# doi-regex

[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fregexhq%2Fdoi-regex.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fregexhq%2Fdoi-regex?ref=badge_shield)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.11164917.svg)](https://zenodo.org/doi/10.5281/zenodo.11164917)

> Regular expression for matching DOIs

Parts of a DOI:
 * Directory Identifier: 10
 * Registrant code: . + [0-9]{2,}
 * Registrant subdivision (optional): . + [0-9]+
 * Suffix: / + any character, case insensitive for ASCII chars (but capitalised
	in the registry), with some characters that _should_ be escaped  
	Recommended encoding: ```"{}^[]`|\\&\/\'<>```  
 	Mandatory encoding: ```%"#?``` and space.

From: http://www.doi.org/doi_handbook/2_Numbering.html#2.2


## Install

```sh
$ npm install --save doi-regex
```


## Usage

```js
var doiRegex = require('doi-regex');

// contains a DOI
doiRegex().test('unicorn 10.1000/xyz000');
//=> true

// is a DOI address
doiRegex({exact: true}).test('unicorn 10.1000/xyz000');
//=> false

doiRegex.declared({exact: true}).test('doi:10.1000/xyz000');
//=> true

doiRegex.groups().test('10.1000/xyz1000.a001');
//=> ['10.1000/xyz1000', '10.1000/xyz1000', '.a001']

'unicorn 10.1000/xyz000 cake 10.1000/xyz001 rainbow'.match(doiRegex());
//=> ['10.1000/xyz000', '10.1000/xyz001']
```


## API

### doiRegex(options)

Returns a regex for matching a DOI.

### doiRegex.declared(options)

Returns a regex for matching a DOI that has been declared with a `doi:` string in front.

### doiRegex.groups(doi)

Returns a regex match object with a final string as the first two indices, and any suffixes that are commonly used for supplemental information if they are attached to the doi. For instance, `10.1000/journal.pone.0000000.g001` would return `10.1000/journal.pone.0000000` and `.g001`. 

#### options.exact

Type: `boolean`  
Default: `false` *(Matches any DOI in a string)*

Only match an exact string.  
Useful with `RegExp#test` to check if a string is an DOI.


## CLI 

A CLI file has been provided. Run any of the examples provided above using your own DOI. For instance: 

```sh
$ node cli-index.js -e 10.000/xyz1000
//=> true
```

Possible Flags:

* `-e`, `--exact`	Find an exact match
* `-d`, `--declared` 	Find a DOI with a 'doi:' prefix
* `-m`, `--match`	Find all matches within the given string
* `-g`, `--groups` Find the stripped DOI and any suffix it might have
* `-h`, `--help` Display usage

## Contribute

Please do!

## License

MIT © [Richard Littauer](http://burntfen.com)


[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fregexhq%2Fdoi-regex.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fregexhq%2Fdoi-regex?ref=badge_large)

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