You may want to store the compiled regexp in some top level var, eg.

```python
WIN_CR_RE = re.compile(r"\r(?!\n)|(?<!\r)\n")
# ... later
pygmented = WIN_CR_RE.sub("\r\n", pygmented)
```