Should I have posted my answer as a comment?
What is meta?
- Any Stack Exchange user can ask a question
- The community provides support, votes on ideas, and reports bugs
- Your voice helps shape the way Stack Exchange operates
IMO, no. You can sometimes best help a user by solving the problem they're trying to solve (parsing HTML) rather than the problem they think they're trying to solve (parsing HTML with regex). Some users get self-righteous about it and downvote your answer, but you're not the asker's slave; you don't need to bow to their every whim, especially if there doesn't seem to be a good reason for needing to use a particular tool or method.
Post what you think is best for the problem at hand. I've found I get rewarded for it more often than I am punished. Just don't come across arrogant, of course! No "That's dumb" or anything :P
Yes, you should have posted your comment as a comment.
Better would be to answering how to solve this the way as the OP asked whenever possible and then at the bottom of the answer subtly remark it as an unrelated note that there are much better alternatives to the solution the OP is trying to use and elaborate it as well.
If it's not possible or not easily possible at all, then you should elaborate that part in detail as well. Just saying "Don't use solution X, you should use solution Y" without further elaboration is IMO not an answer, but more a comment. In your case, try to explain in detail why parsing HTML with regex is an insane solution. Although your answer is understood by the community, it might not be understood by the OP.
Both yes and no answers have already been given to this question; the only thing left to say is, it depends.
It can be either extremely helpful or extremely frustrating to be told, "Don't do it like that; do it like this." It can be liberating to know that there is not only a better clunky way, but a smooth, powerful, easy way. However, sometimes a user is already aware of the better way of doing things, but doesn't have that as a possibility.
For example, where I work, I am not able to install software on my computer; indeed, the computer where I do most of my work is not even connected to the internet. Thus, when I ask Vim questions, for example, answers that tell me to just download and install some plugin are helpful if I ever run into the same issue at home, but don't help me at all at work. I really just do want the quick 'n' dirty solution at work because I don't have another option.
So my advice is, make sure the user is aware of the better way of doing it, but be careful with how you phrase it. This:
is a much, much better answer than:
I just read Chichiray's answer more carefully and realized that says some very similar things, even though he began by saying "no". I didn't plagiarize, I promise.