使用python 打开文件并做匹配处理的实例
作者:xinke453 时间:2022-01-15 16:27:30
如下所示:
import os
import re
import string
file = open("data2.txt")
p1 = re.compile(r"^(\d{16})\s+(\d{3})")
re.compile(p1)
for line in file:
print(line)
match1 = re.search(p1,line)
#print(match1.group(0))
sCard = match1.group(1)
sValue=match1.group(2)
print(sCard)
print(sValue)
b = re.findall(r"\d{2}",sCard)
# remove r or one \ if want signle \
c =r'\\x'.join(b)
c= r'\\x'+c
print(c)
来源:https://blog.csdn.net/xinke453/article/details/74180678
标签:python,文件,匹配
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
一个滑动展示的小代码
2011-07-01 12:58:05
python中的global关键字的使用方法
2023-07-15 13:26:50
改善登陆界面的用户体验: 自动聚焦表单
2009-12-09 16:13:00
![](https://img.aspxhome.com/file/UploadPic/200912/9/js_auto_focus_1-62s.png)
SQL Server双服务器架设并数据自动同步教程
2023-07-03 02:59:53
利用ASP.NET MVC和Bootstrap快速搭建响应式个人博客站(一)
2023-07-06 23:47:39
![](https://img.aspxhome.com/file/2023/6/56056_0s.jpg)
oracle 性能优化建议小结
2010-04-22 16:32:00
SQL Server中选出指定范围行的SQL语句写法
2008-12-09 15:04:00
PHP基础之运算符的使用方法
2023-11-20 17:33:55
![](https://img.aspxhome.com/file/2023/7/111357_0s.png)
Mootools 1.2教程(11)——Fx.Morph、Fx选项和Fx事件
2008-12-04 16:03:00
Oracle性能究极优化 上第1/2页
2010-07-30 13:26:00
ASP连接SQL2005数据库连接代码
2011-03-25 10:44:00
详解使用Visual Studio Code对Node.js进行断点调试
2023-07-01 07:32:34
![](https://img.aspxhome.com/file/2023/0/55900_0s.jpg)
对Python Pexpect 模块的使用说明详解
2022-10-24 02:14:09
《色彩解答》系列之三 色彩对比
2008-02-17 14:40:00
![](https://img.aspxhome.com/file/UploadPic/20082/17/2008217144426798s.png)
有时应该告诉我,但有时不应该告诉我
2009-03-19 13:40:00
![](https://img.aspxhome.com/file/UploadPic/20093/19/login1-79s.jpg)
IE6 bug: 消失的绝对定位元素
2009-12-04 12:11:00
php通过exif_read_data函数获取图片的exif信息
2023-10-27 09:01:44
Python3 venv搭建轻量级虚拟环境的步骤(图文)
2022-11-26 08:47:16
![](https://img.aspxhome.com/file/2023/5/68385_0s.jpg)
10张动图学会python循环与递归问题
2023-08-23 10:55:42
![](https://img.aspxhome.com/file/2023/8/62878_0s.gif)
发现IE6下URL path不会自动补全
2009-03-31 12:52:00