python - 捕获电影标题组
问题描述
我正在尝试从电影标题中捕获以下组:
file = "The Great Home Se01E01 Meatballs for Dinner"
<show> = "The Great Home"
<season> = "Se01"
<episode> = "E01"
<title> = "Meatballs for Dinner"
目前,我只部分设法捕获和使用以下代码:
import re
file = "The Great Home Se01E01 Meatballs for Dinner"
seasonEpID = re.search(r'(\bS/?.+\d{1,2})+(E/?.+\d{1,2})', file)
print(seasonEpID.groups())
它返回以下内容:
('Se01', 'E01')
一个人怎么能捕捉到四个组<show>
, <season>
, <episode>
, <title>
?
解决方案
我将使用re.findall
以下正则表达式模式:
^(.*?)\s+(Se\d+)(E\d+)\s+(.*)$
示例脚本:
file = "The Great Home Se01E01 Meatballs for Dinner"
parts = re.findall(r'^(.*?)\s+(Se\d+)(E\d+)\s+(.*)$', file)
print(parts)
这打印:
[('The Great Home', 'Se01', 'E01', 'Meatballs for Dinner')]
推荐阅读
- azure - Azure SendGrid 每个键的不同域品牌
- php - 如果有可用描述,如何仅显示类别描述和标题?
- android - NestedScrollview 不适用于 Drawerlayout
- tensorflow - 如何从训练有素的 keras 模型中找到等效的 ONNX 运算符?
- vba - VBA中的索引匹配匹配/vlookup
- jmeter - 如何在 JMeter 中执行线程以完全填充以下场景?
- javascript - Electron.js:如何为一个窗口创建一个单独的下载 webContents.session?
- sql-server - 从哪里获得 Sql server 2019 32 位
- typescript - Angular 12 Chart.js - 无法显示甜甜圈
- postman - Postman - 从 NodeJS 运行的 Newman