fork download
  1. s='start of text\n line 1\n line 2\n\nline 3\n line 4\n\nstop matching after this\nline 5\n line 6\n\nline 7'
  2. res = []
  3. stop = False # Flag to know where to stop matching
  4. for line in s.splitlines():
  5. if line.strip().startswith('stop matching after this'):
  6. stop = not stop # Reverse the flag
  7. if stop:
  8. res.append(line) # Add line as is
  9. else:
  10. res.append(line.lstrip()) # Add the line stripped from the left
  11.  
  12. print("\n".join(res))
Success #stdin #stdout 0.02s 9172KB
stdin
Standard input is empty
stdout
start of text
line 1
line 2

line 3
line 4

stop matching after this
line 5
    line 6

line 7