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: {$_}$/"; }
In reply to Re: Re^4: A NOT in regular expressions (thanks)
by idsfa
in thread A NOT in regular expressions
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |