import re


def get_pattern_cols(cols, pos_pattern=None, neg_pattern=None):
    """Get columns names from a list that matches ``pos_pattern``,
    but does not match ``neg_pattern``.

    If a column name matches both ``pos_pattern`` and ``neg_pattern``, it is excluded.

    Parameters
    ----------
    cols : `List` ['str']
        Usually column names of a DataFrame.
    pos_pattern : regular expression
        If column name matches this pattern, it is included in the output.
    neg_pattern : regular expression
        If column name matches this pattern, it is excluded from the output.

    Returns
    -------
    pattern_cols : `List` ['str']
        List of column names that match the pattern.
    """
    if pos_pattern is None:
        pos_pattern_cols = []
    else:
        pos_regex = re.compile(pos_pattern)
        pos_pattern_cols = [col for col in cols if pos_regex.findall(col)]
    if neg_pattern is None:
        neg_pattern_cols = []
    else:
        neg_regex = re.compile(neg_pattern)
        neg_pattern_cols = [col for col in cols if neg_regex.findall(col)]

    pattern_cols = [col for col in cols if
                    col in pos_pattern_cols and col not in neg_pattern_cols]

    return pattern_cols