<p <%=foo1%> <%=foo2%> >
<h3><%=bar1%></h3>
<h4><%=bar2%></h4>
</p>
I am looking for a regular experssion the result of which should be foo1 and foo2 because those are the values declared as attributes. bar1 and bar2 should not be captured because they are not declared as attributes.
I am using ruby 1.8.7.
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:
Gives you:
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.