Evaluate content before passing to regex.sub

Closes #1708
Wondering if safer/cleaner to instead do `content = unicode(content)` at the top of this func? Thoughts?