<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def re_sub(pattern, repl, string, count=0, flags=0, custom_flags=0):
 """Replace regular expression. Parameters pattern : `str` or `_sre.SRE_Pattern` Compiled regular expression. repl : `str` or `function` Replacement. string : `str` Input string. count: `int` Maximum number of pattern occurrences. flags : `int` Flags. custom_flags : `int` Custom flags. """

    if custom_flags & ReFlags.OVERLAP:
        prev_string = None
        while string != prev_string:
            prev_string = string
            string = re.sub(pattern, repl, string, count, flags)
        return string
    return re.sub(pattern, repl, string, count, flags)