def convert_to_regex(rules_dict: dict, rule_num: int, depth: int=0) -> str:
    """Convert rule to its regex equivalent and return it.

    Args:
        rules_dict: Dictionary of rule_num: rule.
        rule_num: Key for rules_dict corresponding to rule to be converted.
        depth: Number of recursive calls to the function. Defaults to 0 and
               used to set a limit on processing of loops.

    Returns:
        The regex string equivalent of the rule at key rule_num in rules_dict
        (to a capped depth).

    """
    if depth > 15:
        return ''

    if rules_dict[rule_num] in ('a', 'b'):
        return rules_dict[rule_num]

    rules = []
    for branches in rules_dict[rule_num].split('|'):
        branch_answer = ''
        for branch_num in branches.split():
            branch_re = convert_to_regex(rules_dict, branch_num, depth + 1)
            branch_answer += branch_re
        rules.append(branch_answer)

    return '(' + '|'.join(rules) + ')'