title: Extract substring between 2 strings in python
body: <p>I have a python dataframe with a string column that I want to separate into several more columns.</p>
  
  <p>Some rows of the DF look like this:</p>
  
  <pre><code>COLUMN
  
  ORDP//NAME/iwantthispart/REMI/MORE TEXT
  /REMI/SOMEMORETEXT
  /ORDP//NAME/iwantthispart/ADDR/SOMEADRESS
  /BENM//NAME/iwantthispart/REMI/SOMEMORETEXT
  </code></pre>
  
  <p>So basically i want everything after '/NAME/' and up to the next '/'. However. Not every row has the '/NAME/iwantthispart/' field, as can be seen in the second row.</p>
  
  <p>I've tried using split functions, but ended up with the wrong results.</p>
  
  <pre><code>mt['COLUMN'].apply(lambda x: x.split('/NAME/')[-1])
  </code></pre>
  
  <p>This just gave me everything after the /NAME/ part, and in the cases that there was no /NAME/ it returned the full string to me.</p>
  
  <p>Does anyone have some tips or solutions? Help is much appreciated! (the bullets are to make it more readable and are not actually in the data).</p>