def _split(string, max_split, remove_empty_matches, matching_function, *
    args, **kwargs):
    """
    Splits a string using a given matching-function that matches the separator.

    This function implements general features needed from the split functions
    in this module (the max-split and remove-empty-matches features).

    :param string:               The string where to split.
    :param max_split:            Defines the maximum number of splits. If 0 or
                                 less is provided, the number of splits is not
                                 limited.
    :param remove_empty_matches: Defines whether empty entries should
                                 be removed from the result.
    :param matching_function:    The matching function. It must return
                                 MatchObject's containing the matched
                                 split-separator.
    :param args:                 Positional arguments to invoke the
                                 matching_function with.
    :param kwargs:               Key-value arguments to invoke the
                                 matching_function with.
    """
    last_end_pos = 0
    for match in matching_function(*args, **kwargs):
        split_string = string[last_end_pos:match.start()]
        last_end_pos = match.end()
        if not remove_empty_matches or len(split_string) != 0:
            yield split_string
            max_split -= 1
            if max_split == 0:
                break
    if not remove_empty_matches or len(string) > last_end_pos:
        yield string[last_end_pos:]
