:ss:"" / Sample xml text with a variety of tag types :ds:&'"<>"=\:ss / find the delimiters :sp:&'"!?/]-"=\:ss / find indices "helper" characters for (sp)ecial tag types / this produces a list of indices for each helper character ss@sp+1 / look for the characters following a helper character ss@sp-1 / look for the characters preceding a helper character (sp:&'"!?/]-"=\:ss)+\:/:-1 1 / Both!! ds[0]?sp-1 / See which characters preceding helper chars are opening delimeters ~^ds[0]?sp-1 / We don't need to know which particular delimiter / Just that there is one ~^ds?'(sp:&'"!?/]-"=\:ss)+\:/:-1 1 / Both! &''~^ds?'(sp:&'"!?/]-"=\:ss)+\:/:-1 1 / Find the indices into the lists of special characters / Find the indices of the actual characters (adjusting back) :sp:-1 1+'sp@'/:&''~^ds?'(sp:&'"!?/]-"=\:ss)+\:/:-1 1 qs:&'"'\""=\:x / Find both single and double quotes / Now to tackle comments and CDATA sp[1] / closing special delimiters sp[1;4 3] / find "->" and "]>" ss@cl:sp[1;4 3]-2 / Look back a couple of characters "-]"='ss@cl / find "-->" and "]]>" cl:2+cl@'&'"-]"='ss@cl / Keep track of where we found this / Now look for openers ss@(op:sp[0;0])+\:2+!7 / Look for the first seven characters after " -->" / Comments don't nest! / Actually, this is illegal syntax. "<" must only be used to open a tag :ss0:" -->" / Nothing wrong with this, though / The comment is closed by the first closing comment :tst:"(open close) close) (open close)" / Let's make it look simpler :oc:&'"()"=\:tst / indices of open and closed characters (#'oc)#'1 -1 / replace open indices with 1's and close indices with -1's (,/(#'oc)#'1 -1)@g: