拆分re.匹配对象类型单词
我有此代码扫描我的电子邮件并返回一个重要的识别号码及其相应日期。我正在尝试将数字和日期分为由列分开的单独子字符串(最终计划是将所有信息都输入CSV),但是我会收到以下错误:attributeError:'re..match'对象没有属性'分裂'。任何帮助都将受到赞赏。这是我的代码:
pattern = re.compile(r'[a-zA-Z]+[0-9]+ [0-9]+/[0-9]+/[0-9]+')
matches = pattern.finditer(body)
for match in matches:
matches.split()
我希望输出看起来如下:
AAA111111, 1/1/2022
BBB222222, 1/1/2022
等等。目标是将其变成我可以在其他地方导入的CSV
,这是进入身体的原因:
'' 感谢您的跟进。这是您订单的更新。
PUU128377 5/22/2023
PUN102938 11/1/2024
PUU012938 10/01/2025
提出任何其他问题 ''
带有扩展信息的新电子邮件
PUU128377 Line 20 Seq 1 5/22/2023
PUN102938 Line 100 Seq 8 11/1/2024
PUU012938 Line 120 Seq 4 1/1/2025
I have this code that scans my emails and returns an important identifying number and its corresponding date. I am trying to split the number and the date into separate substrings separated by columns (ultimate plan is to get them all the info into a csv), but I get the following error: AttributeError: 're.Match' object has no attribute 'split'. Any help is appreciated. Here's my code:
pattern = re.compile(r'[a-zA-Z]+[0-9]+ [0-9]+/[0-9]+/[0-9]+')
matches = pattern.finditer(body)
for match in matches:
matches.split()
I expect the output to look like the following:
AAA111111, 1/1/2022
BBB222222, 1/1/2022
and so on. Goal is to turn it into a csv that I can import elsewhere
Also, here is what goes into body:
''
Thanks for following up. Here’s an update on your orders.
PUU128377 5/22/2023
PUN102938 11/1/2024
PUU012938 10/01/2025
Reach out with any further questions
''
New email with extended info
PUU128377 Line 20 Seq 1 5/22/2023
PUN102938 Line 100 Seq 8 11/1/2024
PUU012938 Line 120 Seq 4 1/1/2025
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试:
这将创建
data.csv
文件:编辑:带有新输入的更新答案
Try:
This creates
data.csv
file:Edit: Updated answer with new input