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()

打印内容:

相关推荐
丙氨酸長鏈13 小时前
[Bukkit插件开发]手持发射器箭矢机枪 教学文档 面向Python/C#开发者入门Java与Bukkit API
java·python·c#
旋生万物13 小时前
电磁力 = 螺旋联络的 90° 旋转?麦克斯韦方程组的几何重构
人工智能·python·算法·机器学习·copilot·世界模型·物理ai
久久学姐13 小时前
【AI问答】python引入其他模块的对象
python·绝对导入·相对导入·目录结构·模块导入
always_TT14 小时前
【Python requirements.txt 依赖管理】
开发语言·python
Logintern0914 小时前
py文件开头为什么需要加:from __future__ import annotations
开发语言·python
bamb0014 小时前
一个项目带你入门AI应用开发05
python
Python私教14 小时前
Django 6.1 邮件配置大改:旧项目如何平稳升级?
后端·python·django
Python私教14 小时前
Django 6.1 升级避坑:数据库版本不兼容怎么解决?
后端·python·django
Python私教14 小时前
Django 接口开发实测:新手还需要使用 REST 框架吗?
后端·python·django
名字还没想好☜15 小时前
Python concurrent.futures 实战:用 ThreadPoolExecutor 并发处理 + as_completed 收结果
数据库·python·php·并发