fork(2) download
  1. import re
  2. s="""Item 1 ....
  3. Item 2 ....
  4. Item 1 ....
  5. ....
  6. ....
  7. Item 2 ....
  8. Item 1 ....
  9. Item 2
  10. Item 1a ....
  11. ....
  12. ....
  13. ....
  14. ....
  15. Item 2b ...."""
  16. prefixes = ['Item 1', 'Item 1a', 'Item 1b']
  17. suffixes = ['Item 2', 'Item 2a', 'Item 2b']
  18. rx = "(?=^((?:{}).*?^(?:{})))".format("|".join(prefixes), "|".join(suffixes))
  19. all_matches = re.findall(rx, s, re.S | re.M)
  20. print(max(all_matches, key=len))
Success #stdin #stdout 0.02s 27712KB
stdin
Standard input is empty
stdout
Item 1a ....
....
....
....
....
Item 2