import re


def test_valid_patterns(list, pattern):
    """
    Function to facilitate the tests in MyRegExTest class
    :param list: list with strings of valid cases
    :param pattern: a regular expression
    :return: list with the result of all matches
    """
    newList = []
    for item in list:
        matched = re.match(pattern, item)
        if matched is None:
            raise ValueError(item + ' does not match the pattern ' + pattern)
        newList.append(matched.group())
    return newList