title: How to preg_replace_all in the large amount of data
body: <p>I just making an upgrade script for replacing all the MODX snippet tags to a newer format:</p>
  
  <p>Old one: <code>[~123~]</code></p>
  
  <p>New one: <code>[[~123]]</code></p>
  
  <p>(of course, 123 - it is an example — there are a lot of different numbers)</p>
  
  <p>Also I wanted to replace all the custom <strong>old</strong> snippets to a newer ones:</p>
  
  <p>Old snippet format: </p>
  
  <pre><code>[!MySnippetName? &amp;param1=`value1` &amp;param2=`value2` !]
  </code></pre>
  
  <p>New one: </p>
  
  <pre><code>[[!MySnippetName? &amp;param1=`value1` &amp;param2=`value2` ]]
  </code></pre>
  
  <p>(of course, <code>&amp;param1=value1 &amp;param2=value2</code> is just an example and it is different in real snippets)</p>
  
  <p>How to use a preg_replace function to make a global replacements?
  I supposed to create like this:</p>
  
  <pre><code>$doc[ 'content' ] = $this-&gt;preg_replace_all(
          array(
                  '/\[~([0-9]+)~\]/',
                  '\[!LatestUpdates(.*)!\]',
                  '\[!ArticleSummary(.*)!\]',
              ), array(
                  '[[~\1]]',
                  '[[!LatestUpdates\1]]',
                  '[[!ArticleSummary\1]]',
              ),
              $doc[ 'content' ]
          );
  </code></pre>
  
  <p><strong>preg_replace_all</strong> function:</p>
  
  <pre><code>private function preg_replace_all( $find, $replacement, $s )
  {
      while(preg_match($find, $s)) {
          $s = preg_replace($find, $replacement, $s);
      }
      return $s;
  }
  </code></pre>
  
  <p>But it doesn't work. Please help to figure out the problem. Thanks in advance.</p>