import re s=r"""D:\Video\DOTA:龍之血\subtitles\en[cc]\DOTA:龍之血.S01E01.WEBRip.Netflix.en[cc].srt D:\Video\DOTA:龍之血\subtitles\en[cc]\DOTA:龍之血.S01E02.WEBRip.Netflix.en[cc].srt D:\Video\DOTA:龍之血\subtitles\en[cc]\DOTA:龍之血.S01E03.WEBRip.Netflix.en[cc].srt D:\Video\DOTA:龍之血\subtitles\en[cc]\DOTA:龍之血.S01E04.WEBRip.Netflix.en[cc].srt D:\Video\DOTA:龍之血\subtitles\en[cc]\DOTA:龍之血.S01E05.WEBRip.Netflix.en[cc].srt D:\Video\DOTA:龍之血\subtitles\en[cc]\DOTA:龍之血.S01E06.WEBRip.Netflix.en[cc].srt D:\Video\DOTA:龍之血\subtitles\en[cc]\DOTA:龍之血.S01E07.WEBRip.Netflix.en[cc].srt D:\Video\DOTA:龍之血\subtitles\en[cc]\DOTA:龍之血.S01E08.WEBRip.Netflix.en[cc].srt D:\Video\DOTA:龍之血\subtitles\ja\DOTA:龍之血.S01E01.WEBRip.Netflix.ja.srt D:\Video\DOTA:龍之血\subtitles\ja\DOTA:龍之血.S01E02.WEBRip.Netflix.ja.srt D:\Video\DOTA:龍之血\subtitles\ja\DOTA:龍之血.S01E03.WEBRip.Netflix.ja.srt D:\Video\DOTA:龍之血\subtitles\ja\DOTA:龍之血.S01E04.WEBRip.Netflix.ja.srt D:\Video\DOTA:龍之血\subtitles\ja\DOTA:龍之血.S01E05.WEBRip.Netflix.ja.srt D:\Video\DOTA:龍之血\subtitles\ja\DOTA:龍之血.S01E06.WEBRip.Netflix.ja.srt D:\Video\DOTA:龍之血\subtitles\ja\DOTA:龍之血.S01E07.WEBRip.Netflix.ja.srt D:\Video\DOTA:龍之血\subtitles\ja\DOTA:龍之血.S01E08.WEBRip.Netflix.ja.srt D:\Video\DOTA:龍之血\subtitles\zh-Hant\DOTA:龍之血.S01E01.WEBRip.Netflix.zh-Hant.srt D:\Video\DOTA:龍之血\subtitles\zh-Hant\DOTA:龍之血.S01E02.WEBRip.Netflix.zh-Hant.srt D:\Video\DOTA:龍之血\subtitles\zh-Hant\DOTA:龍之血.S01E03.WEBRip.Netflix.zh-Hant.srt D:\Video\DOTA:龍之血\subtitles\zh-Hant\DOTA:龍之血.S01E04.WEBRip.Netflix.zh-Hant.srt D:\Video\DOTA:龍之血\subtitles\zh-Hant\DOTA:龍之血.S01E05.WEBRip.Netflix.zh-Hant.srt D:\Video\DOTA:龍之血\subtitles\zh-Hant\DOTA:龍之血.S01E06.WEBRip.Netflix.zh-Hant.srt D:\Video\DOTA:龍之血\subtitles\zh-Hant\DOTA:龍之血.S01E07.WEBRip.Netflix.zh-Hant.srt D:\Video\DOTA:龍之血\subtitles\zh-Hant\DOTA:龍之血.S01E08.WEBRip.Netflix.zh-Hant.srt""" s2=r"""EP01 雷霆的話.MP4 EP02 一無所有的公主.MP4 EP03 無處之地.MP4 EP04 本書結尾的怪獸.MP4 EP05 火誡.MP4 EP06 騎士、死亡和魔鬼.MP4 EP07 說出來.MP4 EP08 對弈.MP4""" a=sorted([_ for _ in list(filter(None, s.split('\n')))]) b=sorted([_ for _ in list(filter(None, s2.split('\n')))], key=lambda _:re.match(r"(?P<p>EP?\d+\s?)?(?P<n>.*?)\..*", _).group('p')) for i, _ in enumerate(a): print('ren "{}" "{}{}"\n'.format(_,b[i%len(b)],re.match(r".*?(?P<f>(?:.(?!\.))+$)",_).group('f')))
Standard input is empty
ren "D:\Video\DOTA:龍之血\subtitles\en[cc]\DOTA:龍之血.S01E01.WEBRip.Netflix.en[cc].srt" "EP01 雷霆的話.MP4.srt" ren "D:\Video\DOTA:龍之血\subtitles\en[cc]\DOTA:龍之血.S01E02.WEBRip.Netflix.en[cc].srt" "EP02 一無所有的公主.MP4.srt" ren "D:\Video\DOTA:龍之血\subtitles\en[cc]\DOTA:龍之血.S01E03.WEBRip.Netflix.en[cc].srt" "EP03 無處之地.MP4.srt" ren "D:\Video\DOTA:龍之血\subtitles\en[cc]\DOTA:龍之血.S01E04.WEBRip.Netflix.en[cc].srt" "EP04 本書結尾的怪獸.MP4.srt" ren "D:\Video\DOTA:龍之血\subtitles\en[cc]\DOTA:龍之血.S01E05.WEBRip.Netflix.en[cc].srt" "EP05 火誡.MP4.srt" ren "D:\Video\DOTA:龍之血\subtitles\en[cc]\DOTA:龍之血.S01E06.WEBRip.Netflix.en[cc].srt" "EP06 騎士、死亡和魔鬼.MP4.srt" ren "D:\Video\DOTA:龍之血\subtitles\en[cc]\DOTA:龍之血.S01E07.WEBRip.Netflix.en[cc].srt" "EP07 說出來.MP4.srt" ren "D:\Video\DOTA:龍之血\subtitles\en[cc]\DOTA:龍之血.S01E08.WEBRip.Netflix.en[cc].srt" "EP08 對弈.MP4.srt" ren "D:\Video\DOTA:龍之血\subtitles\ja\DOTA:龍之血.S01E01.WEBRip.Netflix.ja.srt" "EP01 雷霆的話.MP4.srt" ren "D:\Video\DOTA:龍之血\subtitles\ja\DOTA:龍之血.S01E02.WEBRip.Netflix.ja.srt" "EP02 一無所有的公主.MP4.srt" ren "D:\Video\DOTA:龍之血\subtitles\ja\DOTA:龍之血.S01E03.WEBRip.Netflix.ja.srt" "EP03 無處之地.MP4.srt" ren "D:\Video\DOTA:龍之血\subtitles\ja\DOTA:龍之血.S01E04.WEBRip.Netflix.ja.srt" "EP04 本書結尾的怪獸.MP4.srt" ren "D:\Video\DOTA:龍之血\subtitles\ja\DOTA:龍之血.S01E05.WEBRip.Netflix.ja.srt" "EP05 火誡.MP4.srt" ren "D:\Video\DOTA:龍之血\subtitles\ja\DOTA:龍之血.S01E06.WEBRip.Netflix.ja.srt" "EP06 騎士、死亡和魔鬼.MP4.srt" ren "D:\Video\DOTA:龍之血\subtitles\ja\DOTA:龍之血.S01E07.WEBRip.Netflix.ja.srt" "EP07 說出來.MP4.srt" ren "D:\Video\DOTA:龍之血\subtitles\ja\DOTA:龍之血.S01E08.WEBRip.Netflix.ja.srt" "EP08 對弈.MP4.srt" ren "D:\Video\DOTA:龍之血\subtitles\zh-Hant\DOTA:龍之血.S01E01.WEBRip.Netflix.zh-Hant.srt" "EP01 雷霆的話.MP4.srt" ren "D:\Video\DOTA:龍之血\subtitles\zh-Hant\DOTA:龍之血.S01E02.WEBRip.Netflix.zh-Hant.srt" "EP02 一無所有的公主.MP4.srt" ren "D:\Video\DOTA:龍之血\subtitles\zh-Hant\DOTA:龍之血.S01E03.WEBRip.Netflix.zh-Hant.srt" "EP03 無處之地.MP4.srt" ren "D:\Video\DOTA:龍之血\subtitles\zh-Hant\DOTA:龍之血.S01E04.WEBRip.Netflix.zh-Hant.srt" "EP04 本書結尾的怪獸.MP4.srt" ren "D:\Video\DOTA:龍之血\subtitles\zh-Hant\DOTA:龍之血.S01E05.WEBRip.Netflix.zh-Hant.srt" "EP05 火誡.MP4.srt" ren "D:\Video\DOTA:龍之血\subtitles\zh-Hant\DOTA:龍之血.S01E06.WEBRip.Netflix.zh-Hant.srt" "EP06 騎士、死亡和魔鬼.MP4.srt" ren "D:\Video\DOTA:龍之血\subtitles\zh-Hant\DOTA:龍之血.S01E07.WEBRip.Netflix.zh-Hant.srt" "EP07 說出來.MP4.srt" ren "D:\Video\DOTA:龍之血\subtitles\zh-Hant\DOTA:龍之血.S01E08.WEBRip.Netflix.zh-Hant.srt" "EP08 對弈.MP4.srt"