title: How to replace a substring with help of preg_replace
body: <p>I have a string that consists of repeated words. I want to replace a substring 'OK' located between 'L3' and 'L4'. Below you can find my code:</p>
  
  <pre><code>$search = "/(?&lt;=L3).*(OK).*(?=L4)/";
  $replace = "REPLACEMENT";
  $subject = "'L1' =&gt; ('Vanessa', 'Prague', 'OK'), 'L2' =&gt; ('Alex', 'Paris', 'OK'), 'L3' =&gt; ('Paul', 'Paris', 'OK'), 'L4' =&gt; ('John', 'Madrid', 'OK')";
  $str = preg_replace($search, $replace, $str);
  </code></pre>
  
  <p>If I use that pattern with preg_match, it finds a correct substring(third 'OK'). However, when I apply that pattern to preg_replace, it replaces substring that matches the full pattern, instead of the parenthesized subpattern. </p>
  
  <p>So could you please give me an advice what I should change in my code? I know that there are plenty amount of similar questions about regex, but as I understand my pattern is correct and I'm only confused with preg_replace function</p>