def apply_and_get_result(self, string):
        """
        Perform the substitution represented by this object on string and return
        the result.
        """
        if self.is_multiline:
            compiled_pattern = re.compile(self.pattern, re.MULTILINE)
        else:
            compiled_pattern = re.compile(self.pattern)

        result = re.sub(compiled_pattern, self.repl, string)
        return result

        Perform the substitution represented by this object on string and return
        the result.
        
eg/substitute.py