title: php preg_replace, replace all span tags with data Attribut from span tag
body: <p>I would like to replace all span tags in PHP with its data-snippet-php content.
  Example:
  Given string:</p>
  
  <pre><code>$str = 'text &lt;span data-snippet-php ="do magic"&gt;Hello World&lt;/span&gt; text';
  </code></pre>
  
  <p>Wanted string:</p>
  
  <pre><code>$str = 'text do magic text';
  </code></pre>
  
  <p>Replace the span tag with the data-snippet-php value.</p>
  
  <p>This works so far in the example: <a href="https://regex101.com/r/XhaEA9/1/" rel="nofollow noreferrer">https://regex101.com/r/XhaEA9/1/</a>
  However, it only works correctly with one span tag. Everything between the first and second match will be swallowed.
  What is the correct pattern?</p>
  
  <pre><code>$re = '/&lt;span.*?data-snippet-php="(.*?)".*?&gt;.*?&lt;\/span&gt;/m';
  $str = 'HTML Code &lt;span class="block" title="Label: Titel" data-snippet-php="&lt;?php _e(\'Titel\',\'grid_test\') ?&gt;" editable="false"&gt;[ Titel ]&lt;/span&gt;: &lt;span class="block" title="Datenfeld: Titel" data-snippet-bind="#: post_title #" editable="false"&gt;{ post_title }&lt;/span&gt; text text text &lt;span class="block" title="Label: Desc" data-snippet-php="&lt;?php _e(\'Desc\',\'grid_test\') ?&gt;" editable="false"&gt;[ Desc ]&lt;/span&gt;: text text text';
  $subst = '$1';
  $result = preg_replace($re, $subst, $str);
  $result ==&gt; 
  'HTML Code &lt;?php _e('Titel','grid_test') ?&gt;: &lt;?php _e('Desc','grid_test') ?&gt;: text text text';
  </code></pre>
  
  <p>This result is wrong, I want this result:</p>
  
  <pre><code>$result ==&gt; 
  'HTML Code &lt;?php _e('Titel','grid_test') ?&gt;: &lt;span class="block" title="Datenfeld: Titel" data-snippet-bind="#: post_title #" editable="false"&gt;{ post_title }&lt;/span&gt; text text text &lt;?php _e('Desc','grid_test') ?&gt;: text text text';
  </code></pre>