fork download
  1. import re
  2. text = """[SAMPLE]\n{\n[MS]\n{\nlots of text...\n;Mass % BPI\n238.85 0.943\n247.64 0.984\n378.65 0.990\n...\n}\n[CHROMATOGRAM]\n{\nlots of text...\n}\nlots of text...\n[MS]\n{\n;Mass % BPI\n238.85 0.943\n247.64 0.984\n378.65 0.990\n...\n}\nlots of text...\n{\n;Mass % BPI\n238.85 0.943\n247.64 0.984\n378.65 0.990\n...\n}\n}\n[SAMPLE]\n{\n[MS]\n{\nlots of text\n;Mass % BPI\n238.85 0.943\n247.64 0.984\n378.65 0.990\n...\n}\n[CHROMATOGRAM]\n{\nlots of text...\n}\nlots of text...\n[MS]\n{\n;Mass % BPI\n238.85 0.943\n247.64 0.984\n378.65 0.990\n...\n}\nlots of text...\n{\n;Mass % BPI\n238.85 0.943\n247.64 0.984\n378.65 0.990\n...\n}\n}"""
  3. list_of_results = re.findall(r'\[SAMPLE][^[]*(?:\[(?!SAMPLE])[^[]*)*', text)
  4. print( list_of_results )
  5.  
Success #stdin #stdout 0.03s 9612KB
stdin
Standard input is empty
stdout
['[SAMPLE]\n{\n[MS]\n{\nlots of text...\n;Mass   % BPI\n238.85  0.943\n247.64  0.984\n378.65  0.990\n...\n}\n[CHROMATOGRAM]\n{\nlots of text...\n}\nlots of text...\n[MS]\n{\n;Mass   % BPI\n238.85  0.943\n247.64  0.984\n378.65  0.990\n...\n}\nlots of text...\n{\n;Mass   % BPI\n238.85  0.943\n247.64  0.984\n378.65  0.990\n...\n}\n}\n', '[SAMPLE]\n{\n[MS]\n{\nlots of text\n;Mass   % BPI\n238.85  0.943\n247.64  0.984\n378.65  0.990\n...\n}\n[CHROMATOGRAM]\n{\nlots of text...\n}\nlots of text...\n[MS]\n{\n;Mass   % BPI\n238.85  0.943\n247.64  0.984\n378.65  0.990\n...\n}\nlots of text...\n{\n;Mass   % BPI\n238.85  0.943\n247.64  0.984\n378.65  0.990\n...\n}\n}']