Python3 获取一大段文本之间两个关键字之间的内容方法
作者:丿灬安之若死 时间:2022-01-17 15:03:31
用re或者string.find.以下是re代码
import re
#文本所在TXT文件
file = '123.txt'
#关键字1,2(修改引号间的内容)
w1 = '123'
w2 = '456'
f = open(file,'r')
buff = f.read()
#清除换行符,请取消下一行注释
#buff = buff.replace('\n','')
pat = re.compile(w1+'(.*?)'+w2,re.S)
result = pat.findall(buff)
print(result)
来源:https://blog.csdn.net/mp624183768/article/details/79661978
标签:Python3,关键字
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
典型的三行二列居中高度自适应css布局
2008-02-22 16:02:00
![](https://img.aspxhome.com/file/UploadPic/20082/22/2008222164924132s.gif)
python模拟菜刀反弹shell绕过限制【推荐】
2023-07-13 12:56:18
oracle SQL命令大全
2009-07-02 11:55:00
python修改包导入时搜索路径的方法
2023-05-12 07:40:23
Pytorch使用shuffle打乱数据的操作
2021-10-03 08:33:31
PHP实现基于3DES算法加密解密字符串示例
2023-08-15 18:48:35
![](https://img.aspxhome.com/file/2023/9/55419_0s.png)
教你学会使用Python正则表达式
2023-01-17 14:08:56
![](https://img.aspxhome.com/file/2023/1/98981_0s.jpg)
js实现QQ邮箱邮件拖拽删除功能
2023-09-07 04:31:05
基于Python实现一个简易的数据管理系统
2023-08-14 11:49:38
![](https://img.aspxhome.com/file/2023/4/92274_0s.png)
使用python+poco+夜神模拟器进行自动化测试实例
2022-12-19 09:09:29
![](https://img.aspxhome.com/file/2023/8/92178_0s.jpg)
基于Python实现主机远程控制
2023-11-24 17:27:31
![](https://img.aspxhome.com/file/2023/5/95175_0s.gif)
一个挺酷的星级投票效果
2010-08-03 12:44:00
![](https://img.aspxhome.com/file/UploadPic/20108/3/star-63s.png)
php隐藏IP地址后两位显示为星号的方法
2023-08-16 13:05:17
Python下载网络小说实例代码
2023-08-01 18:22:17
![](https://img.aspxhome.com/file/2023/2/69502_0s.jpg)
在SQL触发器或存储过程中获取在程序登录的用户
2012-01-29 18:01:32
Python中__repr__和__str__区别详解
2022-02-17 04:45:25
python中matplotlib的颜色以及形状实例详解
2021-06-30 23:04:35
![](https://img.aspxhome.com/file/2023/2/105592_0s.png)
OBJECTPROPERTY与sp_rename更改对象名称的介绍
2012-01-29 18:04:39
手把手教你使用Python创建微信机器人
2022-02-11 14:12:29
![](https://img.aspxhome.com/file/2023/4/64724_0s.jpg)
HTML的基本元素
2010-03-16 12:39:00