<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def split_dict(data, filter_keys=None):
 # flake8: noqa """Deep extract matching keys into separate dict. Extracted data is placed into another dict. The function returns two dicts; one without the filtered data and one with only the filtered data. The dicts are structured so that they can be recombined into one dict. To accomplish that, all values extracted from lists are replaced with a `None` and `None` values are placed in extracted lists to maintain the position of the extracted data. One example use case for this is for extracting out sensitive data from a dict for encryption or separate storage: SENSITIVE_KEYS = [ 'apikey', re.compile('password$'), re.compile('^password'), ] safe, sensitive = split_dict(data, filter_keys=SENSITIVE_KEYS) original = merge_dictionary(safe, sensitive) :param filter_keys: a list of keys considered sensitive :returns: a tuple of two dicts; (original-extracted, extracted) """

    def key_match(key, filter_keys):
        """Determine whether or not key is in filter_keys."""
        if key in filter_keys:
            return True
        if key is None:
            return False
        for reg_expr in [pattern for pattern in filter_keys
                         if hasattr(pattern, "search")
                         and callable(getattr(pattern, "search"))]:
            if reg_expr.search(key):
                return True
        return False

    def recursive_split(data, filter_keys=None):
        """Return split dict or list if it contains any matching fields."""
        if filter_keys is None:  # Safer than default value
            filter_keys = []
        clean = None
        matching = None
        has_matching_data = False
        has_clean_data = False
        if isinstance(data, list):
            clean = []
            matching = []
            for value in data:
                if isinstance(value, dict):
                    clean_value, matching_value = recursive_split(
                        value, filter_keys=filter_keys)
                    if matching_value is not None:
                        matching.append(matching_value)
                        has_matching_data = True
                    else:
                        matching.append({})  # placeholder
                    if clean_value is not None:
                        clean.append(clean_value)
                        has_clean_data = True
                    else:
                        clean.append({})  # placeholder
                elif isinstance(value, list):
                    clean_value, matching_value = recursive_split(
                        value, filter_keys=filter_keys)
                    if matching_value is not None:
                        matching.append(matching_value)
                        has_matching_data = True
                    else:
                        matching.append([])  # placeholder
                    if clean_value is not None:
                        clean.append(clean_value)
                        has_clean_data = True
                    else:
                        clean.append([])
                else:
                    clean.append(value)
                    matching.append(None)  # placeholder
                    has_clean_data = True
        elif isinstance(data, dict):
            clean = {}
            matching = {}
            for key, value in data.items():
                if key_match(key, filter_keys):
                    has_matching_data = True
                    matching[key] = value
                elif isinstance(value, dict):
                    clean_value, matching_value = recursive_split(
                        value, filter_keys=filter_keys)
                    if matching_value is not None:
                        has_matching_data = True
                        matching[key] = matching_value
                    if clean_value is not None:
                        has_clean_data = True
                        clean[key] = clean_value
                elif isinstance(value, list):
                    clean_value, matching_value = recursive_split(
                        value, filter_keys=filter_keys)
                    if matching_value is not None:
                        has_matching_data = True
                        matching[key] = matching_value
                    if clean_value is not None:
                        has_clean_data = True
                        clean[key] = clean_value
                else:
                    has_clean_data = True
                    clean[key] = value
        if has_matching_data:
            if has_clean_data:
                return clean, matching
            else:
                return None, matching
        else:
            if has_clean_data:
                return clean, None
            else:
                return data, None
    clean, matching = recursive_split(data, filter_keys=filter_keys)
    return clean, matching