fork download
  1. import re
  2.  
  3. text = """1
  4. 00:00:05.210 --> 00:00:07.710
  5. In this lecture, we're
  6. going to talk about
  7.  
  8. 2
  9. 00:00:07.710 --> 00:00:10.815
  10. pattern matching in strings
  11. using regular expressions.
  12.  
  13. 3
  14. 00:00:10.815 --> 00:00:13.139
  15. Regular expressions or regexes
  16.  
  17. 4
  18. 00:00:13.139 --> 00:00:15.825
  19. are written in a condensed
  20. formatting language."""
  21.  
  22.  
  23. regex = r"^\d+\r?\n\d{2}:\d{2}:\d{2}\.\d{3} -->.*\r?\n((?:(?!\d+\r?\n\d\d:).*(?:\r?\n|$))*)"
  24. content = [i for i in re.split(r"(?<=\.)\s+", re.sub(r"[\r\n]+", " ", "".join(re.findall(regex, text, re.M)))) if i]
  25. print(content)
Success #stdin #stdout 0.02s 9572KB
stdin
Standard input is empty
stdout
["In this lecture, we're going to talk about pattern matching in strings using regular expressions.", 'Regular expressions or regexes are written in a condensed formatting language.']