in reply to Re^4: A NOT in regular expressions (thanks)
in thread A NOT in regular expressions

Cribbing from Mastering Regular Expressions' section on removing C-style quotes ...

qr{ <% [^%]* %+ ( [^>%] [^%]* %+ )* > }x;

appears to properly handle every example in this thread, as well as not taking forever on a failed match.

# Test Script #Uncomment this next line for WAAAYYY too much info #use re 'debug'; $cleanup= qr{ <% [^%]* %+ ( [^>%] [^%]* %+ )* > }x; @test= ( "stuff <% junk %> more stuff <% more junk %> end", "stuff <% junk% %> more stuff", "Go <% now %> to <% your %> home <% if %> you <% can %>", "<% %%>", "<%replace here%%>but not here%>", "1 <% xxx%%> 2 <%%> 3 <%>%> 4 <% >% %> 5 <%%%% xxx %%%%> 6 ", "<% %%> %>", "<%abcdefg>"x500, "<% %% %>"); foreach(@test) { print "-"x60,$/,"Test: {$_}$/"; s/$cleanup//g; print "Result: {$_}$/"; }

Remember, when you stare long into the abyss, you could have been home eating ice cream.