Skip to content

Commit 13a2654

Browse files
committed
Tested against the DOI spec, closes #2
1 parent bfeb908 commit 13a2654

File tree

4 files changed

+35
-9
lines changed

4 files changed

+35
-9
lines changed

index.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
'use strict';
22

3+
/**
4+
* Parts of a DOI:
5+
* Directory Identifier: 10
6+
* Registrant code: . + [0-9]{4,}
7+
* Registrant subdivision (optional): . + [0-9]+
8+
* Suffix: / + any character, case insensitive for ASCII chars (but capitalised
9+
* in the registry), with some characters that _should_ be escaped.
10+
* Recommended encoding: "{}^[]`|\\&\/\'<>
11+
* Mandatory encoding: %"#? (and space)
12+
* From: http://www.doi.org/doi_handbook/2_Numbering.html#2.2
13+
*/
14+
315
// TODO Capture final segment for fragments
416
// (\\.[a-zA-Z]{1}[0-9]{3})?
5-
var doiRegex = '(10[.][0-9]{4,}(?:[.][0-9]+)*/(?:(?!["&\/\'<>])\\S)+)'
17+
var doiRegex = '(10[.][0-9]{4,}(?:[.][0-9]+)*/(?:(?![%"#? ])\\S)+)'
618
var doiTextPrefix = 'doi\\:'
719

820
var doi = module.exports = function (opts) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "doi-regex",
3-
"version": "0.0.5",
3+
"version": "0.0.6",
44
"description": "Regular expression for matching DOIs",
55
"main": "index.js",
66
"scripts": {

readme.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
> Regular expression for matching DOIs
44
5+
Parts of a DOI:
6+
* Directory Identifier: 10
7+
* Registrant code: . + [0-9]{4,}
8+
* Registrant subdivision (optional): . + [0-9]+
9+
* Suffix: / + any character, case insensitive for ASCII chars (but capitalised
10+
in the registry), with some characters that _should_ be escaped
11+
Recommended encoding: ```"{}^[]`|\\&\/\'<>```
12+
Mandatory encoding: ```%"#? ```(and space)
13+
14+
From: http://www.doi.org/doi_handbook/2_Numbering.html#2.2
15+
516

617
## Install
718

@@ -62,18 +73,17 @@ Useful with `RegExp#test` to check if a string is an DOI.
6273
A CLI file has been provided. Run any of the examples provided above using your own DOI. For instance:
6374

6475
```sh
65-
$ node cli-index.js -e `10.000/xyz1000`
66-
true
76+
$ node cli-index.js -e 10.000/xyz1000
77+
//=> true
6778
```
6879

69-
Run it without arguments to see all possible flags.
70-
7180
Possible Flags:
7281

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

7888
## License
7989

test.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ var _ = require('lodash')
44
var doiRegex = require('./');
55

66
var doi = [
7-
'10.1371/journal.pone.0077056'
7+
'10.0001/journal.pone.000001',
8+
'10.0001/journal/pone.0011111',
9+
'10.0001.112/journal.pone.0011021',
10+
'10.0001/issn.10001'
811
];
912

1013
var doiNot = [
11-
'10.1000//journal.pone.0011111',
1214
'10..1000/journal.pone.0011111',
13-
'1.1/1.1'
15+
'1.1/1.1',
16+
'10/134980',
17+
'10.001/001#00'
1418
];
1519

1620
var doiDeclared = [

0 commit comments

Comments
 (0)