Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/regexhq/doi-regex
Regular expression for matching DOIs
https://github.com/regexhq/doi-regex
doi doi-regex regex regular-expression
Last synced: 13 days ago
JSON representation
Regular expression for matching DOIs
- Host: GitHub
- URL: https://github.com/regexhq/doi-regex
- Owner: regexhq
- License: mit
- Created: 2014-12-02T20:08:58.000Z (about 10 years ago)
- Default Branch: main
- Last Pushed: 2024-06-14T16:11:19.000Z (8 months ago)
- Last Synced: 2024-12-21T18:08:36.972Z (about 1 month ago)
- Topics: doi, doi-regex, regex, regular-expression
- Language: HTML
- Homepage:
- Size: 349 KB
- Stars: 30
- Watchers: 10
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
- Citation: CITATION.cff
Awesome Lists containing this project
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');
//=> falsedoiRegex.declared({exact: true}).test('doi:10.1000/xyz000');
//=> truedoiRegex.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)