import re


def filter_string(str, filters):
    """
    Progressive filtering of a string using search and replace or regex filters.

    Iterate over an array of array pairs using the first as a match and second
    as a replacement. If any additional value added to the pair, run as regex.

    Args:
        str (string): String to run filters against.
        filters (array): Two/Three value array with the first item being a string
            to look up or regex to execute. Second value is a string to replace
            matches with or a callback for regex handling. If a third entry as a
            boolean is supplied, the first entry is handled as a regex query.

    Returns:
        Filtered output of the original input string.
    """

    for filter_set in filters:
        if len(filter_set) > 2:
            str = re.compile(filter_set[0]).sub(filter_set[1], str)

        else:
            str = str.replace(filter_set[0], filter_set[1])
            
    return str