我正在尝试将 mkvinfo 输出中的每一种音频和字幕语言都放入数组中,我已经尝试了各种谷歌搜索和 RegExr 上的正则表达式组合,但没有成功。我的源字符串是| + Muxing application: libmkv 0.6.5| + Writing application: HandBrake rev5474| + Timecode scale: 1000000| + Duration: 6788.031s (01:53:08.031)|+ Segment tracks| + A track| + Track number: 1 (track ID for mkvmerge & mkvextract: 0)| + Track UID: 718870071| + Track type: video| + Lacing flag: 0| + Codec ID: V_MPEG4/ISO/AVC| + CodecPrivate, length 45 (h.264 profile: High @L3.1)| + Default duration: 41.708ms (23.976 frames/fields per second for a video track)| + Default flag: 1| + MinCache: 1| + Video track| + Pixel width: 1280| + Pixel height: 536| + Display width: 1280| + Display height: 536| + A track| + Track number: 2 (track ID for mkvmerge & mkvextract: 1)| + Track UID: 1000053498| + Track type: audio| + Lacing flag: 0| + Codec ID: A_AAC| + CodecPrivate, length 2| + Language: fre| + Default flag: 1| + Audio track| + Sampling frequency: 48000| + Channels: 2| + A track| + Track number: 3 (track ID for mkvmerge & mkvextract: 2)| + Track UID: 1097600287| + Track type: audio| + Lacing flag: 0| + Codec ID: A_AAC| + CodecPrivate, length 2| + Language: eng| + Default flag: 0| + Audio track| + Sampling frequency: 48000| + Channels: 2| + A track| + Track number: 4 (track ID for mkvmerge & mkvextract: 3)| + Track UID: 1976675274| + Track type: subtitles| + Lacing flag: 0| + Codec ID: S_TEXT/UTF8| + Language: fre| + Default flag: 0| + A track| + Track number: 5 (track ID for mkvmerge & mkvextract: 4)| + Track UID: 1930079859| + Track type: subtitles| + Lacing flag: 0| + Codec ID: S_TEXT/UTF8| + Language: fre| + Default flag: 0|+ Cluster使用正则表达式Language:\s([a-z]+)我可以获得所有音频和字幕Language: freLanguage: engLanguage: freLanguage: fre理想的输出是Array( [audio] => Array ( [0] => eng [1] => fre ) [subtitles] => Array ( [0] => fre [1] => fre ))任何帮助将不胜感激,提前致谢,最好
1 回答
互换的青春
TA贡献1797条经验 获得超6个赞
您可以使用交替来匹配 2 个捕获组中的任一值,并使用点匹配换行符(?s)
然后,您可以使用组 1 作为键来组装结果数组,并将组 2 的值添加到组 1 键。
(?s)\+\h+Track type:\h+(audio|subtitles)\b.*?\+\h+Language:\h+([a-z]+)
例如
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
$result = [];
foreach ($matches as $match) {
$result[$match[1]][] = $match[2];
}
print_r($result);
输出
Array
(
[audio] => Array
(
[0] => fre
[1] => eng
)
[subtitles] => Array
(
[0] => fre
[1] => fre
)
)
不需要的更精确的模式可以(?s)匹配Track type:和匹配所有不以 A track 或 Language 开头的行:
^\|\h+\+\h+Track type:\h+(audio|subtitles)(?:\R(?!\|\h+\+\h+(?:[A-Z] track$|Language:)).*)*\R\|\h+\+ Language:\h+([a-z]+)
- 1 回答
- 0 关注
- 73 浏览
添加回答
举报
0/150
提交
取消