import re


def tags_matching_regex(key, regex_str:str, compiled_regex = None):
    """ 
    Returns a list of tags with all tags that match the regular expression
    """

    if compiled_regex is None:
         compiled_regex = re.compile(regex_str)

    tags_list = []

    for tag in key.getTags():
        if compiled_regex.search(tag) is not None:
            tags_list.append(tag)
    
    return tags_list