回复 3# netdzb - >>> import re
- >>> text='''REM DATE 2000
- REM DISCID 980A4C0C
- REM COMMENT "ExactAudioCopy v1.0b4"
- PERFORMER "孙燕姿"
- TITLE "我要的幸福"
- FILE "孙燕姿 - 我要的幸福.wav" WAVE
- TRACK 01 AUDIO
- TITLE "On The Road(Demo1)"
- PERFORMER "孙燕姿"
- INDEX 01 00:00:00
- TRACK 02 AUDIO
- TITLE "我要的幸福"
- PERFORMER "孙燕姿"
- INDEX 01 01:25:27
- TRACK 03 AUDIO
- TITLE "坏天气"
- PERFORMER "孙燕姿"
- INDEX 00 04:58:40
- INDEX 01 05:01:05
- TRACK 04 AUDIO
- TITLE "零缺点"
- PERFORMER "孙燕姿"
- INDEX 00 09:30:22
- INDEX 01 09:32:72
- TRACK 05 AUDIO
- TITLE "开始懂了"
- PERFORMER "孙燕姿"
- INDEX 00 13:11:57
- INDEX 01 13:14:27
- TRACK 06 AUDIO
- TITLE "中间地带"
- PERFORMER "孙燕姿"
- INDEX 00 17:43:72
- INDEX 01 17:46:50
- TRACK 07 AUDIO
- TITLE "相信"
- PERFORMER "孙燕姿"
- INDEX 00 22:15:67
- INDEX 01 22:17:45
- TRACK 08 AUDIO
- TITLE "累赘"
- PERFORMER "孙燕姿"
- INDEX 00 26:47:22
- INDEX 01 26:49:65
- TRACK 09 AUDIO
- TITLE "难得一见"
- PERFORMER "孙燕姿"
- INDEX 00 30:01:30
- INDEX 01 30:03:72
- TRACK 10 AUDIO
- TITLE "害怕"
- PERFORMER "孙燕姿"
- INDEX 00 34:15:45
- INDEX 01 34:18:15
- TRACK 11 AUDIO
- TITLE "星期一天气晴 我离开你"
- PERFORMER "孙燕姿"
- INDEX 00 38:20:67
- INDEX 01 38:23:02
- TRACK 12 AUDIO
- TITLE "On The Road(Demo2)"
- PERFORMER "孙燕姿"
- INDEX 00 42:42:07
- INDEX 01 42:44:52'''
- >>> re.findall(r'TRACK.+?[\n].+?TITLE.+?[\n]',text)
- ['TRACK 01 AUDIO\n TITLE "On The Road(Demo1)"\n', 'TRACK 02 AUDIO\n TITLE "我要的幸福"\n', 'TRACK 03 AUDIO\n TITLE "坏天气"\n', 'TRACK 04 AUDIO\n TITLE "零缺点"\n', 'TRACK 05 AUDIO\n TITLE "开始懂了"\n', 'TRACK 06 AUDIO\n TITLE "中间地带"\n', 'TRACK 07 AUDIO\n TITLE "相信"\n', 'TRACK 08 AUDIO\n TITLE "累赘"\n', 'TRACK 09 AUDIO\n TITLE "难得一见"\n', 'TRACK 10 AUDIO\n TITLE "害怕"\n', 'TRACK 11 AUDIO\n TITLE "星期一天气晴 我离开你"\n', 'TRACK 12 AUDIO\n TITLE "On The Road(Demo2)"\n']
- >>> last=re.findall(r'TRACK.+?[\n].+?TITLE.+?[\n]',text)[-1]
- >>> last
- 'TRACK 12 AUDIO\n TITLE "On The Road(Demo2)"\n'
- >>> last_title=re.search(r'(?<=").+?(?=")',last).group()
- >>> last_title
- 'On The Road(Demo2)'
复制代码
|