import re


def _parse_pattern(pattern: str, path: str, ignore_paren=False) -> dict:
    """Parses patterns that specify information in the filename.
    This is useful for removing artifacts that may be missed by the formatter.

    >>> path = "02 Angela (2020 Remaster).m4a"
    >>> pattern = _parse_pattern('<tracknumber> <title> (<ignore>)', path)
    >>> pattern
    {'tracknumber': '02', 'title': 'Angela', 'ignore': '2020 Remaster'}

    You can replace "ignore" with anything except reserved attributes, or leave it empty:
    >>> pattern = _parse_pattern('<tracknumber> <title> (<>)', path)
    >>> pattern
    {'tracknumber': '02', 'title': 'Angela', '': '2020 Remaster'}

    Only the "title" key is used for searching in this class.
    """

    curr_key = []
    curr_bound = []
    bounds = []
    keys = []
    is_key = False
    for c in pattern:
        if c == "<":
            is_key = True
            if len(curr_bound) > 0:
                bounds.append("".join(curr_bound))
                curr_bound = []
        elif c == ">":
            is_key = False
            if len(curr_key) > 0:
                keys.append("".join(curr_key))
                curr_key = []
        else:
            if is_key:
                curr_key.append(c)
            else:
                curr_bound.append(c)

    if len(curr_bound) > 0:
        bounds.append("".join(curr_bound))

    # finds whatever is outside the bounds
    bounds = [re.escape(s) for s in bounds]
    something = r"([\s\S]+?)"
    regex = something + something.join(bounds)
    vals = re.findall(regex, path)
    return dict(zip(keys, vals[0]))