How does it work? Simple. Firstly, none of <%@> are special chars to RE by themselves. Secondly, the first part (up to the second \s*) matches the start of the interesting chunk from your string, and there's a literal %> at the end. Thirdly, there's a bunch of real RE magic in the middle: ((?:(?!%>).)*)
Looking at that in detail, we see this in expanded form
( # Stash this sub-RE in a variable (?: # Pure grouping of zero-width assertion and matcher (?! %> ) . # any character, as long as it isn't the start of %> ) * # and as many of them as possible ) # That's All Folks!
The key to doing sane parsing is often the negative lookahead assertion. It makes life *so* much easier!