fix: python 2.6 re.sub compatibility

cannot pass flags keyword argument to re.sub
the workaround is to compile the regex first and then perform the
substitution
http://stackoverflow.com/a/17318220/1123985