title: multiple regex captures
body: <p>I need to capture a certain pattern multiple times while also remembering what's before, after and in between. For example:</p>
  
  <blockquote>
    <p>some text "to be captured" some more text "to be captured" some more
    text</p>
  </blockquote>
  
  <p>The only things that are predictable are the tokens that delimit the text to be captured. The captured text itself is different every time. In the end I need to place css spans around those captured parts, like so</p>
  
  <pre><code>some text &lt;span class="a"&gt;"to be captured"&lt;/span&gt; some more text &lt;span
  class="a"&gt;"to be captured"&lt;/span&gt; some more text
  </code></pre>
  
  <p>I tried</p>
  
  <pre><code>if (preg_match("/(.*?)(\".*?\")(.*)/", $line, $m)
      $res .= $m[1] . '&lt;span class="a"&gt;' . $m[2] . '&lt;/span&gt;' . $m[3];
  </code></pre>
  
  <p>It works for a line with only one capture. Using preg_match_all doesn't fix this, probably I will also have to change the regex itself, but I don't know how.</p>