python核心编程:正则表达式练习

本文通过一系列的实例,深入探讨了Python编程中的正则表达式应用,涵盖了匹配、查找、替换等核心操作,旨在提升读者在实际项目中运用正则表达式的能力。
摘要由CSDN通过智能技术生成
#匹配网址
import re
strtest = """
http://www.interoem.com/messageinfo.asp?id=35
http://3995503.com/class/class09/news_show.asp?id=14
http://lib.wzmc.edu.cn/news/onews.asp?id=769
http://www.zy-ls.com/alfx.asp?newsid=377&id=6
http://www.fincm.com/newslist.asp?id=415
"""
new_strtest = re.findall("http://[\w+.|\d+.].*/",strtest)
print("修正前:",strtest)
print("修正后:")
for new in new_strtest:
    print(new)

运行结果:

修正前: 
http://www.interoem.com/messageinfo.asp?id=35
http://3995503.com/class/class09/news_show.asp?id=14
http://lib.wzmc.edu.cn/news/onews.asp?id=769
http://www.zy-ls.com/alfx.asp?newsid=377&id=6
http://www.fincm.com/newslist.asp?id=415

修正后:
http://www.interoem.com/
http://3995503.com/class/class09/
http://lib.wzmc.edu.cn/news/
http://www.zy-ls.com/
http://www.fincm.com/
<
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值