This is a case where I think you're better off doing two passes. First, extract all the <% %> data values that are attributes inside tags. Then, go through and extract off the <% and %>.
For example:
<[^>]*?((?:<%=[^%]*%>\s*)+)[^<]*>
Gives you:
<%=foo1%> <%=foo2%>
Then, a simple
<%=(.*?)%>
on the output from the first regex, gives you foo1, foo2, etc. I've been trying to construct a combined one, but the only way I can see to do that is to use a look-behind operation. I don't think that's supported in Ruby, and regardless since the look-behind would have to match at the same point multiple times, I believe most engines would kick it out.