import re _URL_REGEX = re.compile(r"(https?://[\w\-._~:/?#\[\]@!$&'()*+,;=%]+)") def linkify(text: str) -> str: def repl(match: re.Match) -> str: url = match.group(0) safe = url.replace('"', "%22") return ( f'{url}' ) return _URL_REGEX.sub(repl, text)