import re


def template_pattern_match(results, template_pattern):
    """
    Return templates which match the template pattern. No pattern specified returns all template
    :param results - list of all template
    :param template_pattern - optional wildcard (*) name of template to match
    :return: list of template
    """

    if template_pattern:
        # convert wildcard "*" to regex format ".*"
        pattern = template_pattern.replace("*", ".*")
        compiled = re.compile(pattern)
        return [template for template in results if compiled.match(template['name'])]

    return results