python-正则表达试-实践1

匹配html标签中的任意标签内数据

  1. 匹配所有包含'oo'的单词

    python 复制代码
    import re
    text = "JGood is a handsome boy, he is cool, clever, and so on..."
    re.findall(r'\w*oo\w*', text) 
  2. 匹配 html中title里面的内容

    原文:

python 复制代码
import re
file = r'./202304.html'
f = open(file,'r',encoding='utf-8')
origin_content = f.read()
#r'<title>(.*)</title>'  效果一样
result = re.findall(r'<title>(.*?)</title>',origin_content)
print(result)
f.close()

打印内容:

相关推荐
大圣编蚕10 小时前
Java StringWriter 详解:从入门到实战
java·开发语言·python
for_ever_love__11 小时前
python基础语法学习: requirements.txt
开发语言·python·学习
程序员清风11 小时前
FastAPI 入门:用 Python 快速开发现代后端服务
python·oracle·fastapi
SunnyDays101111 小时前
使用 Python 提取 Word 文档中的表格数据
python·word
for_ever_love__11 小时前
python基础语法学习: 动态类型
开发语言·python·学习
troy12812 小时前
分布式系统框架选型指南:主流框架优缺点深度对比
python·django·pygame
129Lab12 小时前
BMS算法快速原型开发:AI辅助实现扩展卡尔曼滤波(EKF)SOC估算从理论到代码落地
python·嵌入式开发·bms·卡尔曼滤波·电池管理系统·soc估算
萧鼎12 小时前
safetensors 库的安装、核心语法与实战用法,安全保存模型权重
python·开源·教程·python库·safetensors
千里码aicood12 小时前
基于Python语言的测量程序设计
开发语言·python
2601_9623008112 小时前
用PyTorch Lightning简化空间分析:Python和机器学习的力量
python·深度学习·机器学习·空间分析·pytorchlightning