def _match_stack(selector, stack):
    """Match stacks using selector as the comparison var.
    Strings prefixed with ^ will be treated as negative

    Args:
        selector (str|list[str]): String tokens or list used for matching
        stack (:obj:`stackformation.BaseStack`): stack used for comparison. Will match on get_stack_name() and get_remote_stack_name()

    Returns:
        :obj:`stackformation.BaseStack`: If stack matches
        bool: False if selector did not match
    """  # noqa
    if not isinstance(selector, list):
        selector = selector.split(' ')

    selector = [i.lower() for i in selector]

    pos = []
    neg = []
    sn = stack.get_stack_name().lower()
    rn = stack.get_remote_stack_name().lower()
    result = False

    for s in selector:
        if s[0] == "^":
            neg.append(s[1:])
        else:
            pos.append(s)

    for s in pos:
        if (s in sn) or (s in rn):
            result = True

    for s in neg:
        if (s in sn) or (s in rn):
            result = False

    return result