def find_matching(text, pos, char1, char2):
    """Finds the matching closing character char2 corresponding to the opening
    character char1, starting from position pos.
    """
    
    depth = 1
    for i in range(pos, len(text)):
        if text[i] == char1:
            depth += 1
        elif text[i] == char2:
            depth -= 1

        if depth == 0:
            return i

    return -1