title: Velocity - if else elseif end - parity - Regex Matching Invalid sets
body: <p>I am attempting to come up with a regex that will mark invalid sets of if statements in velocity. I want to be able to quickly highlight chunks of code that have problems, or that would otherwise cause a velocity parse error. I am intending to place these inside a sublime syantax highlighting file, so the invalid coloring will highlight these inside sublime.</p>
  <h1>Valid:</h1>
  <p>#if      (starts with)</p>
  <p>#elseif  (any number of these zero, one, or more)</p>
  <p>#else    (must be after any elseif, zero or one)</p>
  <p>#end     (must be last, and must exist)</p>
  <h1>Valid (regex should not match these):</h1>
  <p>[ #if ... #end ]</p>
  <p>[ #if ... #elseif ... #end ]</p>
  <p>[ #if ... #else ... #end ]</p>
  <p>[ #if ... #elseif ... #elseif ... #end ]</p>
  <p>[ #if ... #elseif ... #elseif ... #else ... #end ]</p>
  <p>[ #inline() ... #end ] (these will also be present) <em>(unsure if having other statements inside this will do anything, I believe velocity treats anything except #end, as part of the inline code)</em></p>
  <h1>Invalid (Regex will match):</h1>
  <p>[ #end ]</p>
  <p>[ <strong>#if ... #end</strong> ... #end ]* (technically the same as above)</p>
  <p>[ #if ... <strong>#if ... #end</strong> ]</p>
  <p>[ #elseif ... #end ]</p>
  <p>[ #else ... #end ]</p>
  <p>At this time I am in the brainstorming point, I have a general idea of how to pull this off, but its just complex enough that I see all sorts of tripping points. All of the above will cross multiple lines, and velocity files can become very complex. This is an overarching effort of mine to build out a complete &quot;invalid&quot; highlighting set for Velocity in Sublime, to help my team limit errors we add to our code. Any help would be greatly appreciated. Ill post what I come up with in my comments.</p>