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.

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)