From e9645a070b4771b1da94329d25aa23d8ef1c6793 Mon Sep 17 00:00:00 2001 From: mrvladus Date: Fri, 8 Sep 2023 14:44:04 +0300 Subject: [PATCH] Use regex for urls --- src/utils.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/utils.py b/src/utils.py index d79eb3d8..677c3e86 100644 --- a/src/utils.py +++ b/src/utils.py @@ -22,6 +22,7 @@ import os import json +import re import shutil import uuid @@ -164,14 +165,12 @@ def rm_crossline(self, text: str) -> str: @classmethod def find_url(self, text: str) -> str: """Convert urls to markup. Make sure to escape text before calling.""" - arr: list = text.split(" ") - new_str = [] - for i in arr: - if i.startswith("http://") or i.startswith("https://"): - new_str.append(f'{i}') - else: - new_str.append(i) - return " ".join(new_str) + + string = text + urls = re.findall(r"(https?://\S+)", string) + for url in urls: + string = string.replace(url, f'{url}') + return string class TaskUtils: