一般来说url地址前几位为 http,https或ftp 后面跟:// 再之后可出现任意非空字符 #匹配url地址 url = "https://www.baidu.com" res = re.match("(http|https|ftp)://[^\s]+", url) print(res.group()) 输出结果为 https://www.baidu.com Process finished with exit code 0