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
$ npm install --save doi-regexvar 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']Returns a regex for matching a DOI.
Returns a regex for matching a DOI that has been declared with a doi: string in front.
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.
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.
A CLI file has been provided. Run any of the examples provided above using your own DOI. For instance:
$ node cli-index.js -e 10.000/xyz1000
//=> truePossible Flags:
-e,--exactFind an exact match-d,--declaredFind a DOI with a 'doi:' prefix-m,--matchFind all matches within the given string-g,--groupsFind the stripped DOI and any suffix it might have-h,--helpDisplay usage
Please do!
MIT © Richard Littauer