为了账号安全,请及时绑定邮箱和手机立即绑定

print(re.findall(r'http:.+\.jpg', 'http://123.jpg,http://234.jpg')) # 为啥打印出的是['http:123.jpg,http:234.jpg'], 不是['http:123.jpg', 'http:234.jpg'] ​

print(re.findall(r'http:.+\.jpg', 'http://123.jpg,http://234.jpg'))
# 为啥打印出的是['http:123.jpg,http:234.jpg'], 不是['http:123.jpg', 'http:234.jpg']


正在回答

2 回答

+默认是贪心匹配,可以加?让它变成非贪心匹配,就能够满足你的需求了

print(re.findall(r'http:.+?\.jpg', 'http://123.jpg,http://234.jpg'))

0 回复 有任何疑惑可以回复我~
因为
‘http://123.jpg,http://234.jpg' 也是符合http:开头jpg结尾的 ‘http:省略.jpg'
你这样试下:
print(re.findall(r'http://[\d]+\.jpg',http://123.jpg,http://234.jpg'))

>>> print(re.findall(r'http://[\d]+\.jpg','http://123.jpg,http://234.jpg'))

['http://123.jpg', 'http://234.jpg']


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

print(re.findall(r'http:.+\.jpg', 'http://123.jpg,http://234.jpg')) # 为啥打印出的是['http:123.jpg,http:234.jpg'], 不是['http:123.jpg', 'http:234.jpg'] ​

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号