6 ms·
It's not explicitly stated, but I believe the author's point is that the original question didn't require a recursive solution (because it's only asking about i
by shmageggy 5y ago
It's not explicitly stated, but I believe the author's point is that the original question didn't require a recursive solution (because it's only asking about individual tags, not matching opening tags with their closing partners)
Edit: yes looking at the answers, someone pointed this out in a comment response to the"Chomsky" answer:
> The OP is asking to parse a very limited subset of XHTML: start tags. What makes (X)HTML a CFG is its potential to have elements between the start and end tags of other elements (as in a grammar rule A -> s A e). (X)HTML does not have this property within a start tag: a start tag cannot contain other start tags. The subset that the OP is trying to parse is not a CFG. – LarsH Mar 2 '12 at 8:43
- inopinatus 5y agoLook again. The context is definitely one of identifying tags that should be closed, but aren’t, and being identified thus in order to normalise a malformed document into well-formed XHTML. It is not prominently stated, but it is nevertheless the case. Consequently, balance matters. The clue is in the title: “match open tags”, for which the body text has only one part of the author’s train of thought (i.e identifying the opening tag). Further discussion of matching the closing tag is omitted from the body of the question, and many people forget (or disregard) the nuanced difference in the title at this point in their read-through, not stopping to ponder “why the heck would they just want the opening tags? what have I missed here about the context?” and instead treating it like some particularly awful and weirdly contrived exam question, as in the article at the top. The final confirmation of all this is in the question history of the question author around the same date: it’s definitely what they were working on. Consequently, our zalgo-spewing correspondent has it right, they should use a parser, and in addition the question should’ve received feedback early to help them describe the context more clearly. That all this was never properly clarified is a failure of moderation, and further a demonstration of how many folks struggle to challenge (or even identify) their own assumptions.
- goto11 5y ago"Match open tags" obviously refers to writing a regular expression which matches opening tags, not to pair opening tags with end tags. If you look at the regex which the OP themself suggests, it is clearly only intended to match opening tags (excluding self-closing tags), not search for corresponding end-tags.
- inopinatus 5y agoWell, as now expressed at hopefully sufficient length, it doesn’t just say solely that, unless one a) disregards the difference in phrasing, and then b) disengages any sense of purpose and practical utility and instead treats it like a badly worded test question. It’s kind of a shibboleth, in a way, for developer sensitivity to actual needs, as opposed to getting hung up on how clever they are.
- jcelerier 5y ago> disengages any sense of purpose and practical utility and instead treats it like a badly worded test question. Who are you to know the purpose and utility better than the person who asked the question ?
- inopinatus 5y agoOh, are they here? It’d be fascinating to hear from them. Alternatively, perhap, that hostile tone is suggesting I’m personally unqualified to interpret loosely framed questions? I suppose, since I’ve only been doing it for a few decades, I’m definitely a novice by any standard, and my tendency to observe and follow up on anomalous, incomplete, subtly conflicting, or otherwise inexplicable requirements by investigating both the timeline and substance of the original context, and the apparent motivations and outcome preferences of the author, is sheer beginners luck, and any uptick in stakeholder utility that from time to time accompanies amending recommendations following such investigative and analytical activity a sheer coincidence! So that must be it - as you can probably tell from all this smug, empty bravado, I’m really just sharing pure speculation, wild guesswork, total fluke, impertinent leaps of inferential faith, only just grasping at the vague outline of my own blind spots et cetera et cetera, and consequently yes, I’d love to hear the original intent restated from the horse’s mouth, too; but, for the meantime, I’ll read the tealeaves, systematically analyse and synthesise to the best of my ability, describe and discuss any substantive points of comprehension that I think might help enrich, or at any rate challenge, a reader’s perspective (including my own), and cross my fingers hoping to read, mark, and inwardly digest what new understanding or revealed wisdom as I can - even when it comes, as it has there and here, via diacritical allegory and dialectical hellfire. Or, finally, if you just want the TL;DR version, the reason I feel unshakeably comfortable asserting that the question author's actual purpose is normalising a nonconforming document into XHTML, by balancing open & close tags, is because they said so. It's in an answer comment about halfway down the first page. > "Can you provide a little more information on the problem you're trying to solve" "Determining all the tags that are currently open, then compare that against the closed tags in a separate array" If that's not enough, here are quotes from their other questions, posted in the minutes and hours prior: "How to balance tags with PHP", and "I need to write a function which closes the opened HTML tags." Sometimes, we just have to bother reading what's in front of us.