diff --git a/src/lib/utils.py b/src/lib/utils.py index e0e01b4..e97dcd2 100644 --- a/src/lib/utils.py +++ b/src/lib/utils.py @@ -138,4 +138,18 @@ def url_is_valid(url: str) -> bool: r'(?:/?|[/?]\S+)$' # /, /path, or /path?query=string , re.IGNORECASE) - return True if url_regex.match(url) else False \ No newline at end of file + return True if url_regex.match(url) else False + +def remove_special_chars(filename, replacement=""): + """Removes special characters from a filename and replaces them with a chosen character. + + Args: + filename: The filename to be sanitized. + replacement: The character to replace special characters with (default: "_"). + + Returns: + The sanitized filename. + """ + # Regular expression to match special characters (excluding alphanumeric, underscore, and dot) + pattern = r"[^\w\._]+" + return re.sub(pattern, replacement, filename) \ No newline at end of file