题解 | #查找网址-正则匹配或者直接遍历#
正则查找网址
https://www.nowcoder.com/practice/d22cc21332c24d7ea1dae179025b8cf5
# 匹配正则表达式匹配有多少位
# re.match()函数从字符串的开头开始匹配
# re.search()函数从任意位置开始匹配 
# re.compile()函数将规则编译后使用findall()函数匹配所有的结果
# re.sub(pattern,rep,string,max)函数用来替换符合的串
# match().span()返回匹配的字符串范围
# 1.常用方法:直接写逐位匹配记录长度
# while True:
#     try:
#         s = input()
#         s1 = 'https://www'
#         countNum = 0
#         for i in range(0,len(s1),1):
#             if s1[i] == s[i]:
#                 countNum += 1
#         print("(0, "+str(countNum)+')')
#     except:
#         break
# 2.使用自带函数库re的match()函数从开始匹配字符串,span()函数输出匹配的范围
import re
while True:
    try:
        print(re.match('https://www',input(),flags=True).span())
    except:
        break
#python面试##Python开发实习##python入门##打开Python的大门##Python工程师#
 投递华为等公司10个岗位
投递华为等公司10个岗位 查看30道真题和解析
查看30道真题和解析