(pattern: str)
return pattern
Translate the user pattern into a regex. This function assumes that the given
    pattern is valid and has been normalized beforehand.
Translate the user pattern into a regex. This function assumes that the given
    pattern is valid and has been normalized beforehand.
Translate the user pattern into a regex . This function assumes that the given pattern is valid and has been normalized beforehand .
def translate_user_pattern(pattern: str) -> str:
    """
    Translate the user pattern into a regex. This function assumes that the given
    pattern is valid and has been normalized beforehand.
    """

    # Escape each special character
    pattern = "".join(
        f"\\{char}" if char in REGEX_SPECIAL_CHARS else char for char in pattern
    )

    # Handle start/end of pattern
    if pattern[-1] != "/":
        pattern += "$"
    if pattern[0] == "/":
        pattern = "^" + pattern[1:]
    else:
        pattern = "(^|/)" + pattern

    # Replace * and ** sequences
    pattern = re.sub(r"\\\*\\\*/", "([^/]+/)*", pattern)
    pattern = re.sub(r"\\\*", "([^/]+)", pattern)

    return pattern
def translate_user_pattern ( pattern : str ) -> str : # Escape each special character pattern = "" . join ( f"\\{char}" if char in REGEX_SPECIAL_CHARS else char for char in pattern ) # Handle start/end of pattern if pattern [ - 1 ] != "/" : pattern += "$" if pattern [ 0 ] == "/" : pattern = "^" + pattern [ 1 : ] else : pattern = "(^|/)" + pattern # Replace * and ** sequences pattern = re . sub ( r"\\\*\\\*/" , "([^/]+/)*" , pattern ) pattern = re . sub ( r"\\\*" , "([^/]+)" , pattern ) return pattern