There is such a text:

Start Line 1 Line 2 Line 3 Line 4 Line 5 ... Line N End 

Question: How can I get everything between "Start" and "End", taking into account that there can be absolutely any text between them, with different indents .

  • 2
    And how have you tried to solve this? And in absolutely any text start and end can enter? - Viktorov
  • "\n".join(text.split("\n")[1:-1]) - Mikhail Murugov
  • any text can be entered between the "Start" and "End" lines - Coffee inTime

1 answer 1

 text = "Start\nLine 1\nLine 2\nLine 3\nLine 4\nLine 5\n...\nLine N\nEnd" start = 'Start' end = 'End' pattern = text[text.find(start)+len(start):text.rfind(end)]