用于检查字符串中 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 关于生日祝福语简短古文