import re


def select(name, include=None, exclude=None):
    """
    Checks whether name is selected based on an include and an exclude filter.
    If include is defined it is applied first. 
    Exclude is applied only if the name is included.
    """

    # filter pipelines
    if include is not None:
        if isinstance(include, str):
            if re.match(include, name) is None:
                return False
        elif name not in include:
            return False

    if exclude is not None:
        if isinstance(exclude, str):
            if re.match(exclude, name) is not None:
                return False
        elif name in exclude:
            return False

    return True