title: Splitting up string of text based on keywords python
body: <p>I have a string of text like this:</p>
  
  <pre><code>'tx cycle up.... down
  rx cycle up.... down
  phase:...
  rx on scan: 123456
  tx cycle up.... down
  rx cycle up.... down
  phase:...
  rx on scan: 789012
  setup
  tx cycle up.... down
  rx cycle up.... down
  tx cycle up.... down
  rx cycle up.... down'
  </code></pre>
  
  <p>I need to split this string up into a list of strings that are split up into these chunks:</p>
  
  <pre><code>['tx cycle up.... down rx cycle up.... down phase:.... rx on scan: 123456', 
   'tx cycle up.... down rx cycle up.... down phase:.... rx on scan: 789012',
   'tx cycle up... down rx cycle up.... down',
   'tx cycle up... down rx cycle up.... down']
  </code></pre>
  
  <p>Sometimes they have a 'phase' and 'scan' number but sometimes they do not, and I need this to be general enough to apply to any of these cases and will have to do this to lots of data.</p>
  
  <p>Basically, I want to split it into a list of strings where each element extends from an occurrence of 'tx' to the next 'tx' (including the first 'tx' but not the next one in that element). How can I do this?</p>
  
  <p>Edit: Suppose that in addition to the string of text above I have other strings of text that appear like this:</p>
  
  <pre><code>'closeloop start
  closeloop ..up:677 down:098
  closeloop start
  closeloop ..up:568 down:123'
  </code></pre>
  
  <p>My code is going through each of the strings of text and splitting it into lists with the splitting code. But when it gets to this string of text it won't find anything to split -- so how can I include a command to split at the 'closeloop start' lines if they appear and the tx lines like before if those appear? I tried this code but I got a TypeError:</p>
  
  <pre><code>data = re.split(r'\n((?=tx)|(?=closeloop\sstart))', data)
  </code></pre>