5

Consider this question as an example. The one who put the close votes on that question as a dupe of the canonical How do you parse and process HTML/XML in PHP? also provide regex only answers to these type of parsing html string with regex questions. Here's the following on my mind regarding closing and answering,

  • I need to provide a comment below the question regarding parsing html files with regex, "regex is an ugly way to parse html or xml files. You need to use a dom parser". Assume that i post the above as a comment. What if the op says "Yeh, i know that but it won't be a problem for me." . In that case, what i do next? May i provide a regex answer?

  • May i abruptly close the new questions or the old ones about parsing html files with regex as a dupe of that canonical question? Note that i have a regex dupe hammer.

  • Or did i need to wait for sometime, for the op to accept an answer? If the accepted answer is a regex only answer, then i have to close that corresponding question as a dupe?

  • Or i need to leave those type of questions (by means of closing).

Sorry, if i'm harse. I'm just asking you people for the suggestions.

1

2 Answers 2

3

I think it is our duty to make sure no one else commits the crime of parsing HTML with regexes, so closing it as a duplicate is a good idea to make sure he doesn't get a crappy regex that "kinda works" instead of taking the time to learn how to use an HTML parser.

If the author replies with "Yeh, i know that but it won't be a problem for me", you need to convince him otherwise, unless he has very specific reasons for doing so (like parsing some broken HTML that makes parsers refuse to load them), but in those (rare) cases the author usually would already mention that in his question.

Also, I feel like regex answers are always too localized and provide very little benefit to anyone other than the asker, so these questions aren't a big loss especially when they're asking for something considered bad practice.

2
  • if i close all the new parsing html with regex questions as dupe of that canonical question (according to your first paragraph), op won't get the answer for his problem. Jan 16, 2015 at 5:21
  • @AvinashRaj they can ask a new question about parsing their HTML using whatever parser they choose.
    – user2629998
    Jan 16, 2015 at 5:24
2

A question author's circumstances rarely has bearing on whether or not they've essentially asked a duplicate question - the canonical answer to consuming XML/HTML is to use a parser designed to do it, an answer which applies no matter what kind of elements they're trying to match.

Don't confuse this with more interesting cases that aren't duplicates, such as the DOM changing between parsing, something that the author might not be aware is happening. In other words, while it is the question author's responsibility to make certain that they're asking the right question, don't develop muscle memory that closes anything that looks like regex used to consume XML.

90% of the questions about this can easily be solved by making someone aware of the plethora of great parsing libraries available for practically every language. But there are caveats - not a problem for me and constraints prohibit using a parser because [reason] are two entirely different things. I know I should use a parser, I can't, I need to use this regex - that's a valid question and I don't think undeserving of help if you can offer a relatively sane answer.

In short, most of these should probably be marked as a duplicate. Some of them are more interesting than others, and if you feel like you have a good answer, then answer it. Just look more at the meat of the question than the premise itself, unless your a vegetarian, in which case remember that the stalks are often really chewy.

2
  • 2
    Amusingly, once you make someone aware of the existence of parsing libraries, they will probably have to hightail it out of here because questions asking for recommendations of said libraries would be off-topic.
    – BoltClock
    Jan 16, 2015 at 5:43
  • I won't be happy until we build a library on every single lawn we can find.
    – Tim Post
    Jan 16, 2015 at 6:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .