正则表达式问题适合输出

时间:2014-01-11 18:24:43

标签: python regex

我使用Debian Squeeze作为NAS_OS并且无法安装MKVToolnix来使用此脚本

所以我试着让re.compile套件适合旧的mkvtoolnix输出。

我想知道如何适应这个命令

AUDIO_RE    = re.compile(r"Spur ID (\d+): audio \([A-Z0-9_/]+\) [number:\d+ uid:\d+ codec_id:[A-Z0-9_/]+ codec_private_length:\d+ language:([a-z]{3})")
SUBTITLE_RE = re.compile(r"Spur ID (\d+): subtitles \([A-Z0-9_/]+\) [number:\d+ uid:\d+ codec_id:[A-Z0-9_/]+ codec_private_length:\d+ language:([a-z]{3})(?: track_name:\w*)? default_track:[01]{1} forced_track:([01]{1})")

到该行输出类型?

Track ID 2: audio (A_AC3) [language:ger default_track:1 forced_track:1]
Track ID 3: audio (A_DTS) [language:eng default_track:0 forced_track:0]
Track ID 4: subtitles (S_TEXT/UTF8) [language:eng default_track:0 forced_track:0]

这是我有多远 - 但剧本仍然不想为我工作

AUDIO_RE = re.compile(r"Track ID (\d+): audio \([A-Z0-9_/]+\) [language:[a-z]{3} default_track:[01]{1} forced_track:[01]{1}")
SUBTITLE_RE = re.compile(r"Track ID (\d+): subtitles \([A-Z0-9_/]+\) [language:[a-z]{3} default_track:[01]{1} forced_track:[01]{1}")

脚本我在说什么就在这里

1 个答案:

答案 0 :(得分:0)

匹配音频线(假设您要捕获的只是曲目ID):

Track ID (\d+): audio \([A-Z0-9_/]+\) \[language:[a-z]{3} default_track:[01] forced_track:[01]\]

示例:http://regex101.com/r/pZ6aR5

匹配字幕行(同样的假设):

Track ID (\d+): subtitles \([A-Z0-9_/]+\) \[language:[a-z]{3} default_track:[01] forced_track:[01]\]

示例:http://regex101.com/r/qO1zV0

请注意,在两种情况下,转换\[\]都是匹配文字方括号所必需的。