该结构是一个播放列表列表。播放列表包括:
- 静态文本和日期;
- 1-n 条轨道,由索引、作者、标题组成
STATICTEXT 2011-06-18
---------------------
01. author - title
02. author - title
STATICTEXT 2011-06-19
---------------------
01. author - title
02. author - title
03. author - title
04. author - title
我想捕获一个播放列表列表。在播放列表 block 内,我想捕获其他信息,例如作者和标题。 对我来说,这是嵌套组的一个例子:每个播放列表是一个包含 2 个嵌套组(作者、标题)的组。
我怎样才能做到这一点?
提前致谢。
R.
最佳答案
正则表达式在某些方面表现出色,但并非在所有方面都出色。为该文件编写解析器简单直接。
playlists = new List()
for line in file
if line is blank
continue
if line starts with "STATICTEXT"
playslists.add(playlist)
playlist = new Playlist()
song = parse song //this is something that regex does good
playlist.add(song)
关于c# regex - 组和嵌套组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6402708/