m[ < % (?: [^%]+ | % [^%>] )* %* # I left it as %* so the "insides" can be easily # grouped & captured % > ]x