import re
regex = re.compile(r"^(-\s+.*?)^([^-])", flags=re.MULTILINE | re.DOTALL)
test_str = ("24\n"
"00:03:01,848 --> 00:03:04,893\n"
"- How adorable.\n"
"[both laughing]\n\n"
"48\n"
"00:02:53,798 --> 00:02:54,758\n"
"[clears throat]\n\n"
"49\n"
"00:02:57,552 --> 00:02:59,971\n"
"- [clears throat] Phil.\n"
"What can I get you?")
subst = "$1- $2"
result = regex.sub(subst, test_str)
if result:
print(result)
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