import re
regex = re.compile(r"([0-9]+)\n([0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3}) --> ([0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3})\n(.*?)\n\n", flags=re.DOTALL)
test_str = ("1\n"
"00:01:34,769 --> 00:01:36,168\n"
"FamÃlia Soprano\n\n"
"2\n"
"00:01:36,304 --> 00:01:37,737\n"
"Peso\n\n"
"3\n"
"00:01:50,117 --> 00:01:53,780\n"
"Ela é dançarina. Broadway,\n"
"shows de verão, essas coisas.\n\n"
"4\n"
"00:01:53,955 --> 00:01:56,924\n"
"Estava me dizendo que Ginny...\n"
"ela dançava, não é?\n\n"
"5\n"
"00:01:57,124 --> 00:01:59,922\n"
"Deu aula de balé anos atrás.\n\n"
"6\n"
"00:02:05,032 --> 00:02:08,195\n"
"- Quem é?\n"
"- Ninguém. Jersey.\n\n"
"7\n"
"00:02:08,369 --> 00:02:10,394\n"
"Do grupo de Ralph Cifaretto.\n\n")
matches = regex.finditer(test_str)
for match_num, match in enumerate(matches, start=1):
print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}")
for group_num, group in enumerate(match.groups(), start=1):
print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html