<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def sub_path(self, path):
 """ If this redirect is a regular expression, it will return a rewritten version of `path`; otherwise returns the `new_path`. """

        if not self.regular_expression:
            return self.new_path
        return re.sub(self.old_path, self.new_path, path)