I'm trying to write a Python script that extracts DOIs from PDFs, using PyPDF2 and the following regex, which I found [here](https://stackoverflow.com/questions/27910/finding-a-doi-in-a-document-or-page/10324802#10324802).

```
\b(10[.][0-9]{4,}(?:[.][0-9]+)*/(?:(?!["&\'])\S)+)\b

```

Although this regex works perfectly when I test it against all kinds of DOIs on [regex101](http://regex101.com/r/tJ6iS8/1), when I use it in the following script, it throws up the error below:

```
#!/usr/bin/env python
# -*- encoding:utf-8 -*-

from PyPDF2 import PdfFileReader
import re
import sys

pdf_file = sys.argv[1]
doi_re = re.compile("\b(10[.][0-9]{4,}(?:[.][0-9]+)*/(?:(?!["&\'])\S)+)\b")
input = PdfFileReader(file(pdf_file, "rb"))
text = input.getPage(0).extractText()

m = doi_re.search(text)
print(m.group(0))

```

```none
File "/Users/fort/Documents/Dropbox/Code/Python/pdf2doi/pdf2doi.py", line 9
doi_re = re.compile("\b(10[.][0-9]{4,}(?:[.][0-9]+)*/(?:(?!["&\'])\S)+)\b")
                                                                          ^
SyntaxError: unexpected character after line continuation character

```

My editor's syntax highlighting suggests that the parser doesn't like `'])\S)+)\b")`, so I tried escaping the double quotes preceding it, which gets rid of that particular problem, i.e.,

```
\b(10[.][0-9]{4,}(?:[.][0-9]+)*/(?:(?![\"&\'])\S)+)\b

```

However, the regex no longer matches DOIs. (Enclosing the regex in single quotes also fixes this syntax error, but with the same outcome.) 

Finally, the script does match some DOIs if I use the following regex instead, but it misses quite a few:

```
10.(\d)+/([^(\s\>\"\<)])+

```

Any ideas on how to get this working would be much appreciated.