capturing an unconstrained repeating pattern
<p>I want the ability to look into a string and find all occurrences of a pattern. This is easy to do with preg_match if you know how many occurrences of the pattern to occur but I can't figure out a way to get this to work when number of occurrences is not known.</p>

<p>Here's an example of a working query for a know set of occurrences:</p>

<pre><code>$pattern = '/\[VAR:(.*)\].*\[VAR:(.*)\].*\[VAR:(.*)\].*\[VAR:(.*)\]/';
$string = "[VAR:one] once apon a time [VAR:two]. And then there was the time that [VAR:three] went to [VAR:four]";
preg_match ( $pattern , $string, $matches );

print_r ( $matches );
</code></pre>

<p>This returns the results you'd expect:</p>

<pre><code>[0] =&gt; [VAR:one] once apon a time [VAR:two]. And then there was the time that [VAR:three] went to [VAR:four]
[1] =&gt; one
[2] =&gt; two
[3] =&gt; three
[4] =&gt; four
</code></pre>

<p>I've tried unsuccessfully variations of <strong>preg_match</strong> and <strong>preg_match_all</strong> with the pattern (both using and not using the PREG_OFFSET_CAPTURE parameter):</p>

<pre><code>$pattern = '/\[VAR:(.*)\]/';
</code></pre>

<p>Any help would be greatly appreciated.</p>
