用于检查字符串中 URL 的 Python 程序
在这种情况下,我们在Python中使用re模块,这里我们接受一个字符串并检查该字符串中是否包含antURL。如果字符串中存在URL,则显示。我们使用findall()方法来解决这个问题。
算法
Step 1: given string as input. Step 2: findall() function is return all non-overlapping matches of pattern in string and in this function the string is scanned left to right and matches are returned in the order found.
示例代码
#从输入字符串中查找URL的程序
import re
def url(str):
#findall()已被使用
#具有字符串中url的有效条件
ur = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\), ]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', str)
return ur
#驱动程序代码
str = 'https://auth.mywebsite.org / user / python program / http://www.mywebsite.org/'
print("网址是:: ", url(str))输出结果网址是:: ['https://auth.mywebsite.org / user / python program / http://www.mywebsite.org/']
热门推荐
10 毛笔哥哥结婚祝福语简短
11 向国庆送祝福语简短
12 建队节祝福语简短
13 朋友喜得外孙简短祝福语
14 小店营业的祝福语简短
15 餐饮生日祝福语简短独特
16 鲜花英语祝福语卡片简短
17 男朋友暴富祝福语简短
18 婶婶拜年祝福语大全简短