'Applies replace function to a given content.'

def _Replace(self, content, replace=None):

    regex = re.compile('"traceBack":    "Traceback[^"\\\\]*(?:\\\\.[^"\\\\]*)*"', re.DOTALL)
    content = regex.sub('"traceBack":    "<traceback    content>"', content)
    if replace:
        if hasattr(replace, '__call__'):
            replace = replace()
        for substr in sorted(replace, key=len, reverse=True):
            repl = replace[substr]
            if hasattr(substr, 'sub'):
                content = substr.sub(repl, content)
            else:
                content = content.replace(substr, repl)
    return content
