title: how to match step by step
body: <p>I have a string variable that gets bigger by concatenation. I need to validate every substring (every loop iteration).</p>
  
  <p>I created a pattern to match the final valid form of the string.</p>
  
  <p>How can I validate every substring (partial but in correct order) of the string ?</p>
  
  <pre><code>    $pattern = "#\{/?MYTAG(\d*)?\}#i" 
      $myString = ''
  
      while (true) {
       $myString .= $aChar;
  
        // {    =&gt; valid
        // {m   =&gt; valid
        // {my  =&gt; valid
        // {myz =&gt; invalid break the loop
  
        if ( preg_match($pattern, $myString) ) {
  
         }
      }
  </code></pre>
  
  <p>I tried to use the <code>?</code> modified to make the character optional. But then it matches the partial string:</p>
  
  <pre><code>// {mysdf
  // it matches {my
  // I want to return false, not get the valid part of the string
  </code></pre>
  
  <p>I hope this makes sense.</p>