This will fail on Windows, because `\` needs to be escaped in regexps.

Simplest fix that comes to mind: `dict(sep=re.escape(os.path.sep))`.

(I'd also change the regexp strings to use a raw strings -- even if `\S` and `\w` aren't currently special in Python string literals.)