4 ms·
The problem is the answers saying "this is not possible". The OP asks a perfectly reasonable question. The answers assume the OP actually meant to ask a differ
by goto11 5y ago
The problem is the answers saying "this is not possible".
The OP asks a perfectly reasonable question. The answers assume the OP actually meant to ask a different question, and they they ridicule the OP for this imagined question.
The question they imagine the OP asks was: "How do I parse an arbitrary HTML document into an element-tree using only a single regular expression and not using any auxiliary data structures, not even the call stack?"
Yes, this is indeed not possible, given the limitations of vanilla regular expressions.
But that was not the question asked.
Of course "use a parser" is perfectly sound advice (if a parser exists which can solve the OP's problem). But saying what the OP is attempting to do (tokenize xhtml) is impossible is absurd, since then it would also be impossible to write a parser!
- inopinatus 5y agoThey're trying to tokenize HTML into two arrays, one being an array of opening tags and one of closing tags, with the hope being to pairwise compare and reconcile the elements of these arrays. The necessary clarification appears further down the page. As for whether it's a reasonable question; as written I beg to differ, it's the opposite, since it does not convey their problem except by a very careful and nuanced reading. The proper response of the S.O. community should've been to aid the OP in clarifying their intentions and amending the question accordingly to bring focus onto their actual problem. That is not what happened. Instead they are indeed on the receiving end of some ridicule, which is shameful, but the advice of "use a parser" would still likely have been a top answer in some fashion had the OP's scattered ancillary questions and clarifications been incorporated. Sadly, only one correspondent of many seems to have seen fit to ask.