You should consider using a triple quoted raw string to avoid having to escape quotes.

```python
line = re.sub(r'''['"]%s['"].*''' % cookbook,
```