<p>I'm having an issue with my regex.</p>

<p>I want to capture &lt;% some stuff %> and i need what's inside the &lt;% and the %></p>

<p>This regex works quite well for that.</p>

<pre><code>$matches = preg_split("/&lt;%[\s]*(.*?)[\s]*%&gt;/i",$markup,-1,(PREG_SPLIT_NO_EMPTY  |  PREG_SPLIT_DELIM_CAPTURE));
</code></pre>

<p>I also want to catch <code>&amp;amp;% some stuff %&amp;amp;gt;</code>   so I need to capture <code>&lt;% or &amp;amp;lt;% and %&gt; or %&amp;amp;gt;</code> respectively.  </p>

<p>If I put in a second set of parens, it makes preg_split function differently (because as you can see from the flag, I'm trying to capture what's inside the parens.</p>

<p>Preferably, it would only match <code>&amp;amp;lt; to &amp;amp;gt; and &lt; to &gt;</code> as well, but that's not completely necessary</p>

<p>EDIT:  The SUBJECT may contain multiple matches, and I need all of them</p>

In your case, it's better to use preg_match with its additional parameter and parenthesis:
```
```
preg_match("#((?:<|&lt;)%)([\s]*(?:[^ø]*)[\s]*?)(%(?:>|&gt;))#i",$markup, $out);
print_r($out);

Array
(
    [0] => <% your stuff %>
    [1] => <%
    [2] => your stuff
    [3] => %>
)
```
```
By the way, check this online tool to debug PHP regexp, it's so useful !
http://regex.larsolavtorvik.com/
EDIT : I hacked the regexp a bit so it's faster. Tested it, it works :-)
Now let's explain all that stuff :
preg_match will store everything he captures in the var passed as third param (here $out)
if preg_match matches something, it will be store in $out[0]
anything that is inside () but not (?:) in the pattern will be stored in $out
The patten in details :
```
```
#((?:<|&lt;)%)([\s]*(?:[^ø]*)[\s]*?)(%(?:>|&gt;))#i can be viewed as ((?:<|&lt;)%) + ([\s]*(?:[^ø]*)[\s]*?) + (%(?:>|&gt;)).

((?:<|&lt;)%) is capturing < or &lt; then %
(%(?:>|&gt;)) is capturing % then < or &gt; 
([\s]*(?:[^ø]*)[\s]*?) means 0 or more spaces, then 0 or more times anything that is not the ø symbol, the 0 or more spaces.
```
```
Why do we use [^ø] instead of . ? It's because . is very time consuming, the regexp engine will check among all the existing characters. [^ø] just check if the char is not ø. Nobody uses ø, it's an international money symbol, but if you care, you can replace it by chr(7) wich is the shell bell char that's obviously will never be typed in a web page.
EDIT2 : I just read your edit about capturing all the matches. In that case, you´ll use preg_match_all the same way.