import re


def rule_to_regex(rule: str, prefix: str = "", suffix: str = "") -> "re.Pattern":
    """Convert a rule from the mast to regular expressions.

    Args:
        rule (str): The line from the mast
        prefix (str, optional): Regex to be prepended
        suffix (str, optional): Regex to be appended

    Returns:
        re.Pattern: A regular expression
    """
    rule = rule.replace(".", "\\.")
    rule = rule.replace("*", "[^/]*")
    rule = rule.replace("#", "(|/|/?.*/?)")
    rule = prefix + rule + suffix
    return re.compile(rule)