用于检查字符串中 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/']
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下