I want to split a string by "&" only in cases when "&" is not between "<%" and "%>" symbols. Between that symbols i have special expressions that i want to ignore during the split. Text is considered as special only when it is between two closest "<%" text "%>". It works like this:
<%qwr<%qrw<%tret%>wet%>qwt => only this is scpecial <%tret%>
<%test142%>wqr%>%<%%>qwr%> => only this is <%test142%> and <%%> is special
Examples:
1) my&string=21<%253&124%> <&> && => ['my', 'string=21<%253&124%> <', '> ', '', '']
2) new<%<&%235<%test&gg%>&test&f => ['new<%<', '%235<%test&gg%>', 'test', 'f']
3) a&<%&qwer&>ty%>&af => ['a', '<%&qwer&>ty%>', 'af']
I tried '\&(?![^<%]*%>)' and (?<!(<%))\&(?!(%>)) but that works wrong.