title: regex to find string within square brackets []
body: <p>I want to capture the text within the square brackets in the html string below.
  But the regex I have below doesn't get 'image' and imagealt' seperately but returns 'image]" alt="[imagealt' instead. If I take out the alt="[imagealt]" from the string it returns as I would expect/want.</p>
  
  <pre><code>$html = '&lt;h2&gt;[title]&lt;/h2&gt;
  &lt;div class="content"&gt;&lt;img src="[image]" alt="[imagealt]" /&gt;&lt;/div&gt;
  &lt;div class="content"&gt;[text]&lt;/div&gt;';
  
  preg_match_all("^\[(.*)\]^",$html,$fields, PREG_PATTERN_ORDER);
  
  echo "&lt;pre&gt;";
  print_r($fields);
  echo "&lt;/pre&gt;";
  
  
  Array
  (
      [0] =&gt; Array
          (
              [0] =&gt; [title]
              [1] =&gt; [image]" alt="[imagealt]
              [2] =&gt; [text]
          )
  
      [1] =&gt; Array
          (
              [0] =&gt; title
              [1] =&gt; image]" alt="[imagealt
              [2] =&gt; text
          )
  
  )
  </code></pre>