title: generic regex for between two parts
body: <p>I'm trying to make a regex which gets the part between two other things using PHP.</p>
  
  <p>I have:</p>
  
  <pre><code>RANDOMSTUFFpart1CONTENTpart2RANDOMSTUFF2
  </code></pre>
  
  <p>So I want to extract CONTENT from between part1 and part2.  </p>
  
  <p>Is there a generic regex expression that I can use, where I just add in code for part1 and part2 and it will work?</p>
  
  <p>Something like:</p>
  
  <pre><code>$part1='';
  $part2='';
  $string='RANDOMSTUFFpart1CONTENTpart2RANDOMSTUFF2';
  $regexthing=...
  </code></pre>
  
  <p><strong>I don't know if Dimitri will return to edit his answer, so I will put the corrected solution here:</strong></p>
  
  <pre><code>$part1 = 'part1';
  $part2 = 'part2';
  $string = 'RANDOMSTUFFpart1CONTENTpart2RANDOMSTUFF2';
  $pattern = '/' . $part1 . '(.*?)' . $part2 . '/';
  preg_match($pattern, $string, $match);
  </code></pre>