fork download
  1. import re
  2. inp_content = ("JOB 1\n"
  3. "CASSCF RESULTS\n"
  4. "***\n"
  5. "Lots of text\n"
  6. "***\n"
  7. "end\n"
  8. "NEVPT2 RESULTS\n"
  9. "***\n"
  10. "Lots of text\n"
  11. "***\n"
  12. "end\n\n"
  13. "JOB 2\n"
  14. "CASSCF RESULTS\n"
  15. "***\n"
  16. "Lots of text\n"
  17. "***\n"
  18. "end\n"
  19. "NEVPT2 RESULTS\n"
  20. "***\n"
  21. "Lots of text\n"
  22. "***\n"
  23. "end\n"
  24. "………………\n"
  25. "JOB 31\n"
  26. "CASSCF RESULTS\n"
  27. "***\n"
  28. "Lots of text\n"
  29. "***\n"
  30. "end\n"
  31. "NEVPT2 RESULTS\n"
  32. "***\n"
  33. "Lots of text\n"
  34. "***\n"
  35. "end")
  36. NEVPT2_Section = r"^NEVPT2.*\n(?:(?!end$).*\n)*end$"
  37. NEVPT2_Section_mathes = re.finditer(NEVPT2_Section, inp_content, re.MULTILINE)
  38.  
  39. for xyz in NEVPT2_Section_mathes:
  40. print(xyz.group())
  41.  
Success #stdin #stdout 0.02s 9560KB
stdin
Standard input is empty
stdout
NEVPT2 RESULTS
***
Lots of text
***
end
NEVPT2 RESULTS
***
Lots of text
***
end
NEVPT2 RESULTS
***
Lots of text
***
end