fork download
  1. import re
  2. p = re.compile(r'(TAG|CORE)START(?: B)?(.+?)(\1END(?: B)?)', re.DOTALL)
  3. test_str = "intro intro intro intro intro intro\nBEGIN A This is where some text starts\nThat is not interesting or wanted\nCORESTART save text A save text A save text A save text A \nsave text A save text A save text A save text A save text A \nsave text A COREEND\nThis is an addendum that is not needed but is just in the way\nEND A outro outro outro outro outro outro \noutro outro outro outro outro outro outro \n.\n\nintro intro intro intro intro intro\nINIT B This is where some text starts\nThat is not interesting or wanted\nTAGSTART B save text B save text B save text B save text B \nsave text B save text B save text B save text B save text B \nsave text B TAGEND B\nThis is an addendum that is not needed but is just in the way\nTERM B outro outro outro outro outro outro \noutro outro outro outro outro outro outro "
  4. print([x.group(2) for x in p.finditer(test_str)])
Success #stdin #stdout 0.01s 9016KB
stdin
Standard input is empty
stdout
[' save text A save text A save text A save text A \nsave text A save text A save text A save text A save text A \nsave text A ', ' save text B save text B save text B save text B \nsave text B save text B save text B save text B save text B \nsave text B ']