11

I recently provided this answer (screenshot for <10k users) to a question about a regex, and it received a downvote fairly quickly. I'd rather get ahead of bad posting habits if I can, so I was curious as to how I could've done better.

I had a couple thoughts on what might have gone wrong, but I'm not too sure about any of them:

  • Maybe the question wasn't focused or researched enough and I shouldn't have answered at all.
  • Maybe my answer was too similar to some of the comments, which I didn't see until after posting.
  • Maybe I should've provided more detail or explanation in my answer.
  • Maybe part of my explanation was factually incorrect.

Is there something I should be doing differently? Was this question worth answering in the first place?

(Note: I have since deleted the post. Whether I absolutely needed to is debatable, but the question got closed and the answer wasn’t doing much good anyways.)

9
  • 7
    I don't see anything wrong with it (maybe the question is a duplicate, but then one would hope that someone would have suggested that...and the regex tag notoriously has absolutely no shortage of duplicate voters...). You could maybe have explained in slightly more detail why .* won't stop at the first double quote, but...I have a hunch that wouldn't have made a difference to whomever the voter is. Your answer was downvoted within 2 seconds of a downvote on the question, so it's likely (but not certain) that the downvote was related to someone not liking the question.
    – Ryan M Mod
    Commented Jul 8 at 22:25
  • 1
    Note that there is not particularly consensus on whether it is appropriate to downvote answers purely because the question should not be answered. (I personally am in favour, per my answer there, largely because it counteracts perverse incentives - although I also try to educate about that.) Commented Jul 8 at 22:29
  • You can’t improve a deleted answer. Commented Jul 9 at 5:09
  • 1
    @SecurityHound Thanks for the information. Obviously I read the answers here and I concluded that my answer wasn't worth leaving up. Now if you're done with the sarcasm, you could follow this up with a suggestion to delete this post on meta, but otherwise, I'm just gonna leave it up because the answers are still useful.
    – Anerdw
    Commented Jul 9 at 5:13
  • 1
    @AndrewYim - I am not being sarcastic. I have a serious problem with submitting an answer then deleting it before making an attempt to improve it. You only deleted it after you ask this question on meta. Commented Jul 9 at 5:15
  • 2
    @SecurityHound The suggestions here essentially amounted to "The question wasn't well-researched; you probably didn't need to bother in the first place." I decided that was a reasonable interpretation, and the best solution I could think of was to delete the answer.
    – Anerdw
    Commented Jul 9 at 5:16
  • Would you mind posting a screenshot of the answer? When it's deleted, most users can't see it except yourself and those with the moderator tools privilege.
    – wjandrea
    Commented Jul 9 at 18:37
  • 4
    @SecurityHound Well, actually you can improve a deleted answer of your own... They can be edited just the same as undeleted answers.
    – TylerH
    Commented Jul 9 at 18:43
  • @wjandrea I updated the post with a screenshot of the answer.
    – TylerH
    Commented Jul 9 at 18:43

2 Answers 2

5

It wasn't me, but...

Maybe the question wasn't focused or researched enough and I shouldn't have answered at all.

I would go with this explanation. Keep in mind that the purpose of questions is to help build a useful repository of knowledge in the Q&A format. This means that we don't write code to specification, so as to be able to provide OP with code that solves OP's problem; we write code because it answers a question that is specific, atomic, and could plausibly be part of some third party's research.

It could be argued that the question is really just a specific case of understanding how .* will operate. But if you see it this way then it should probably be closed as a duplicate instead. And really, to get the question to that point, we would have to filter out the other issues, like:

  • How do I access the text that was matched between the quotes? (also a duplicate, presumably)

  • How do I (in Python) repeat the process for each line of the file, and make a list of those results? (also a duplicate, but not a question about regex; there were several not-quite-right attempts at this question historically and the link here is to my self-answered attempt)

In general, it's really hard to ask and answer regex questions productively. It's really a mini language; the suitable questions are about what the individual pieces do. "Please put some pieces together for me" is clearly not a suitable question, even if the assembly of pieces is a single line of code.

10
  • 4
    This one seems fine, though? It's a focused question someone else might have, not some weird idiosyncratic requirement list. I really lean toward the explanation being the general ... mess ... that is the regex tag and its sometimes overly harsh curation.
    – Ryan M Mod
    Commented Jul 8 at 22:28
  • 1
    Ahhh, although I missed the each line bit in the title... that is arguably unfocused, and the answer doesn't address it, either.
    – Ryan M Mod
    Commented Jul 8 at 22:29
  • 17
    @RyanM honestly I feel like everyone would be happier if we made regex.SE, declared regex questions off topic here, and let them make their own rules. Commented Jul 8 at 22:30
  • 1
    @RyanM looking back on it, I think I agree with this answer. The question was a little lazy and had very little use outside this one application; regardless of focus, it probably just wasn’t worth answering.
    – Anerdw
    Commented Jul 8 at 23:10
  • @KarlKnechtel I'd more like a site with looser rules where tags such as regex, css, html and sql belong. And probably a few other "Not programming but allowed in anyway" tags where curation according to the list of rules designed for programming problems fails. Give the tags a place where questions can be work orders and answers can be code dumps.
    – Gimby
    Commented Jul 9 at 13:50
  • @Gimby there are limits to how far that could go while still really belonging on the Stack Exchange network. But sure. (It's also pretty hard to define the category of "tags such as regex, css, html, and sql" in any objective way that doesn't lead to hurt feelings.) Commented Jul 9 at 15:20
  • 2
    "... let them make their own rules." - For example, no guns, no knives :-)
    – Stephen C
    Commented Jul 10 at 5:06
  • @KarlKnechtel yeah they are tags which deal more with visual results rather than programming problems. "It looks like this, I need it to look like this but if you try to tell me why the change is needed that is probably superfluous as I already know but just need help to connect the dots". I have no idea how to wrap that up into named category.
    – Gimby
    Commented Jul 10 at 7:40
  • @Gimby I agree on the others but SQL is a real programing language and should not belong over there.
    – mousetail
    Commented Jul 11 at 10:31
  • @mousetail I don't know that "real" is well defined here. I think the issue is the nature of the problem domain these languages are aimed at. Commented Jul 11 at 13:12
3

One possible reason (I'm not the voter) is that you missed a requirement: they want an array consisting of the matches from each line. (In your defense, I also missed it on the first pass.)

Arguably, this makes the question a little unfocused, as it's a combination of "match everything between first and last double quotes, including other double quotes, in regex" (I can't find a duplicate for this; this one is close but not quite right, and also confusing) and "get the result of a regex for each line of a line in Python" (duplicate of How to use regexp on file, line by line, in Python).

So it may be a combination of answering a poorly focused question (relatedly, see Karl's comment on this meta question), and doing so incompletely.

You must log in to answer this question.

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