def replace_repeat_character(text, char_1, target, delimiter, char_2=None):
    """
    Replace two characters by a single one.

    Replaces them even if separated by space or delimiter. Also merges any
    adjacent delimiters.

    If char_2 is not provided then it is assumed that char_1 is repeated
    """
    char_2 = char_2 or char_1
    patterns = (
        char_1 + char_2,
        char_1 + delimiter + char_2,
        char_1 + ' ' + char_2)

    text = text.replace(delimiter * 2, delimiter)
    while any(text.find(pattern) > 0 for pattern in patterns):
        for pattern in patterns:
            text = text.replace(pattern, target + delimiter)
        text = text.replace(delimiter + ' ', delimiter)
        text = text.replace(delimiter * 2, delimiter)
    return text