re.sub doesn't accept the flags keyword argument until 2.7, but the same effect can be achieved using re.compile.