import fnmatch
import re


def multiple_filter(strings, patterns, regex=False):
    """ Apply multiple search filters to a sequence of strings

    Args:
        strings (list[str]): A collection of strings to search
        patterns (list[str]): A collection of search patterns, etiher glob
            style or regular expression
        regex (bool): True if ``patterns`` is a set of regular expressions

    Returns:
        list[str]: A subset of ``strings`` that matched a pattern in
            ``patterns``
    """
    if isinstance(patterns, str):
        patterns = (patterns, )
    if not regex:
        patterns = map(fnmatch.translate, patterns)
    regexs = map(re.compile, patterns)

    found = []
    for _regex in regexs:
        for s in strings:
            if _regex.search(s):
                found.append(s)
    uniq_found = sorted(set(found), key=lambda item: found.index(item))
    return uniq_found