/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#()?&//=]*)/
/(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/
def url_encode(text: str):
"url 검출"
# URL 추출할 정규표현식 생성
url_regex = r"(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)"
reg = re.compile(url_regex)
res = reg.search(text)
if res == None:
return text
else:
indexes = res.span()
url_txt = text[indexes[0]:indexes[1]]
return url_txt
https://digitalfortress.tech/tips/top-15-commonly-used-regex/