I have noticed an abundance of answers that consist of nothing but a pattern.

Obviously, not explaining the patterns will lead the (often clueless) OPs to just copy and paste the solutions. Consequently, they will come back each time they have another regular expression problem to solve. We are throwing fish at them instead of teaching them how to fish. This is the opposite of what Stack Overflow is supposed to be: a repository of quality answers.

There has been at least two complaints about the quality of regular expression answers in the past:

The proposed solutions did not yield any improvement IMO. Apart from being almost always Too Localized anyway, a lot of regular expression questions are still answered with one-liners and no explanation of the patterns whatsoever.

Examples for bad regular expression answers:

Examples for better regular expression answers:

As a moderator I can already leave post notices for Insufficient explanations, stating:

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer: please explain why you're recommending it as a solution. Answers that don't explain anything will be deleted. See Good Subjective, Bad Subjective for more information.

However, given the size of the problem, I don't think it's expedient to put these notices below pattern-only answers. My suggestion would be treating answers to regular expression questions that only contain a pattern as Not An Answer from now on.

It is my opinion that people should downvote/flag/delete them, just like they do with link only answers. Moderators should delete them on sight. The community should clearly signal that we do not want those. The hope, of course, is that people will eventually learn that they should provide more comprehensive answers.

But I am open for suggestions on how to treat those.

  • 11
    While I completely agree with you that this is a problem, I still wouldn't consider them "not an answer". – Linuxios Apr 24 '13 at 12:59
  • 3
    @Linuxios - feel free to add explanations to any "naked" regexes you see to prevent their deletion. – ChrisF Apr 24 '13 at 13:00
  • 2
    @ChrisF: Alright. Has this become the new standard? I feel like we should give the community a little more time to respond first. – Linuxios Apr 24 '13 at 13:01
  • 4
    @Linuxios - Not yet, but editing to improve answers as always been part of SO/SE and should be done irrespective of initiatives like this. – ChrisF Apr 24 '13 at 13:02
  • @ChrisF: of course. I just meant "is deleting pattern-only answers moderator policy yet?". – Linuxios Apr 24 '13 at 13:03
  • @Linuxios - not yet. – ChrisF Apr 24 '13 at 13:03
  • 6
    They're no different to any other answer that just has the solution without explaining anything; not entirely unhelpful but also not the best answer they could be. – Anthony Grist Apr 24 '13 at 13:06
  • Users doing such answers should get downvotes en masse. It's a two headed problem, this also trains OPs to continue such mess by accepting (rewarding) such answers. – hakre Apr 24 '13 at 13:12
  • 8
    What we need is a regex to find answers which only contain a regex. How do we get it, hmm, lets make a post on SO. – Dreen Apr 24 '13 at 13:44
  • @user0000001 this query may help you find them more than any regex will: data.stackexchange.com/stackoverflow/query/111136/… – Richard J. Ross III May 1 '13 at 16:29
  • 1
    Posting regex only answers is an efficient way to gain reputation (Not sure if this is a good or bad thing). Also, questions with the regexp tag are usually answered 3 times by different users with the same answer (who get all 1 or 2 upvotes). Editing the question to explain it is not an option IMHO: What answer should you edit (all?) and it does not respect the original author (who just want some quick rep). – Johannes Kuhn May 7 '13 at 14:49
  • @JohannesKuhn It's a bad thing. Stack Overflow is not about reputation farming. It's about providing good answers. It's a learning repository. At least that's the theory, which is not honored by fire and forget answers. Yes, edit or downvote or comment on all. If we do nothing, the situation won't improve. – Gordon May 7 '13 at 15:07
  • I just tried to describe the current situation. I hate editing stuff into a post where the OP might not agree with (esp with my rep<2k). If we edit such answers, we advocate posting such answers, in the hope someone else will voluntarily improve it. I agree that SO is not about rep farming (I know how to do, but I don't do it). – Johannes Kuhn May 7 '13 at 15:15
  • @JohannesKuhn that's okay. You can still downvote and/or comment on these and ask the OP to provide an explanation. – Gordon May 7 '13 at 16:02

Do not delete them on sight.

These answers may not meet the quality standards of the site, but they are useful and valid answers.

I can't tell you how many times I have said to myself "I need a regex for this common pattern. I think I'll Google for a comprehensive regex first before working on building my own", and find a great regex-only SO answer within seconds which provides exactly what I need, or more as I don't always think of every edge case.

Instead do one of the following:

  • Leave a comment asking the answerer to explain the regex.

    Even if you don't get a reply from the person who answered, chances are someone else will see your comment and answer you in the comments, thus providing a more comprehensive answer. You can even edit their explanation into the answer if you want.

  • Post your own answer explaining the regex

    I always try to understand code I get online, and usually upvote a post which explains some code over one that doesn't, as it was actually more helpful to me than the code-only answer. I suspect many other users do the same.

    And if you're going to take the time to provide an explanation for the code someone else wrote, at least you can get some rep from it :)

  • Edit the post yourself to explain the regex, or leave a comment with the explanation

    Might be a bit of a thankless task, however you will be providing a much greater service to the site than simply voting to delete a useful answer. A useful answer with no explanation is still far better than no answer at all, and of course a useful answer with an explanation is best of all.

  • Downvote the post and move on

    Don't remove useful answers that actually answer the question based on their quality, but do downvote them (and perhaps leave a polite comment explaining the reason for the downvote in hopes that others might follow your lead and pressure the OP to correcting the quality problem themselves).

There are many answers on the site that provide just code without an explanation, not just regex-only answers. Sure these aren't great, however they're still valid and useful answers. And with the number of questions SO gets on a daily basis, we need all the correct answers we can get. :)

So rather than discouraging the answerers by deleting their contributions, educate them by explaining how to improve their answers, or by providing an example of how an answer should look by posting your own.

Edit for the current bounty message:

"The answers suggesting editing, commenting and downvoting are quite reasonable and obvious. However, I do not yet see a clear preference of the community whether pattern-only answers should be treated as Not An Answer. This is why I am offering a bounty to get more feedback."

To clarify my answer, I think pattern-only answers can be perfectly valid answers.

They are definitely not optimal, but we have millions of answers which are not optimal, yet are still correct, valid, and useful. I daily see answers posted that are nothing more than code-dumps, and a pattern-only answer is pretty much the same thing.

So treat regex-only answers the same way you would any other code-only answer. Downvote it, edit it, leave comments, etc but don't delete it for being "Not an answer" unless it doesn't actually answer the question.

  • 2
    I disagree that they are useful, but the points you make are reasonable and I think this is indeed what the community at large should do. I disagree that moderators should not delete them on sight though. If we agree that these are Not An Answer, we will treat them accordingly and that means deletion. It's the same way with link only answers. It's not like we actively hunt for them. The majority is flagged to us. But if we see them outside the flag queue, we remove them (well, at least I do). – Gordon Apr 24 '13 at 14:50
  • @Gordon I trust moderators to use their discretion and only delete the ones that don't add any value to the community. There are many regex posts out there of varying quality, many of which do deserve to be deleted, however I also think that a correct answer without an explanation is infinitely better than no answer at all, for both the OP and for others searching for the same regex :) – Rachel Apr 24 '13 at 15:05
  • 1
    @Gordon: Why not convert-to-comment? – Manishearth Apr 24 '13 at 15:27
  • 6
    How does that help anything, @Manishearth? If the answer does add something to the question (by, say, answering it) then converting it to a comment just makes that less visible. – Shog9 Apr 24 '13 at 15:31
  • @Shog9: Hm. Right. Either way, they do need fixing. – Manishearth Apr 24 '13 at 15:36
  • 2
    Sure, @Manish - but given that half the advice here so far is "edit" and neither authors nor 3rd-parties can edit a comment... I would advise against that option in all but weird edge-cases. – Shog9 Apr 24 '13 at 15:42
  • @Shog9: I guess the reason I want to convert to comment is that we need an effective deterrent to these, but I guess downvoting would work too. – Manishearth Apr 24 '13 at 15:45
  • 2
    Convert to comment is a great idea if you're trying to demonstrate the sorts of responses that should be posted as comments. If you're just looking for a kinder, gentler form of "delete", it is just confusing. – Shog9 Apr 24 '13 at 15:46
  • I am particularly appreciative of "post your own answer explaining the regex." While a naked regex statement may not be a complete answer, it's still an answer. As far as I'm concerned, improving upon existing answers is fair game. – Aza May 4 '13 at 18:56

If you find a "naked" regex and you understand it you can (indeed should) edit the answer to document/explain it for the benefit of the rest of us.

This will prevent otherwise correct answers being deleted should this suggestion ever become policy.

  • 1
    You should probably spare your time if the answer has been accepted already. Then it is too late I fear. – hakre Apr 24 '13 at 13:11
  • @hakre - Fair point, but accepted answers can still be down-voted/flagged and deleted by moderators should this become policy. – ChrisF Apr 24 '13 at 13:12
  • Does this imply that users who happen upon such answers, and do not have the required knowledge to edit them, should not bother flagging? – Bart Apr 24 '13 at 13:13
  • I didn't meant "too late for flagging/deleting" but "too late for being the edit of use". By accepting the OP already showed that the answer was accepted, e.g. did the job. The OP won't come back here. It is too late to explain anything (given that the question itself often is too localized, too). – hakre Apr 24 '13 at 13:13
  • 5
    @hakre even if the OP does not come back, you can edit it for future visitors. – Gordon Apr 24 '13 at 13:16
  • @Gordon: Sure, afer editing the quesiton to a generalization as well. But I only do that, if I find the answer (e.g. via goolge) on SO, improving question and answers. But that is just very exceptional (given that there are so fantastic tutorials about regular expressions). – hakre Apr 24 '13 at 13:18

Generally, the questions which can be answered by one line regex would be too localized.

As someone who spends his time on the science sites, I'm of the opinion that an answer must have at least some explanatory text. The text could explain how the answer works, or how one can get to a similar answer in a similar situation, or something else. But there must be text.

That's not the current policy, though, code only answers seem fine. That's fine with me.

However, an answer that's just a snippet of a regex should IMO be converted into a comment unless it gets edited with a short explanation. It answers the question, but it's not really helpful to others.

I don't really like one-line snippet answers, and I personally feel like they ought to be converted to comments, but I wouldn't if I have the power to. This isn't the sort of policy we should enforce, so downvoting and leaving a comment is the best solution.

  • 1
    I disagree that they are not helpful to others and that they are generally too localized. I search for Regex patterns all the time, and have found the one-line regex answers on SO very useful on many occasions. It's not that I don't know how to write a regex, but it's more efficient to do a quick search for one before figuring out the logic and writing up one of my own. It makes me a more efficient programmer. – Rachel Apr 24 '13 at 14:18
  • 5
    @Rachel that's a misconception IMO. The thing copy and paste usually makes you more efficient at is introducing bugs. Even if you can quickly find a Regex, you still have to read and understand it. If there is no explanation (or if the code is not sufficiently self describing) you are left with your own knowledge (which will stay limited when you just c&p). The time you then need to figure out what the Regex really does is likely the same as when you had written it yourself. – Gordon Apr 24 '13 at 15:07
  • 3
    @Gordon Copy-Paste is definitely a great way to introduce bugs, however Read-Understand-Copy-Paste is a great way to be a faster and more efficient programmer, and I usually don't have a problem reading a regex :) – Rachel Apr 24 '13 at 15:21
  • 3
    @Rachel: That's you, because you are good at making regexes and are just being lazy (I do that too :P). But for a large majority of people who haven't understood how regex works, this is just a disaster waiting to happen. – Manishearth Apr 24 '13 at 15:26
  • 2
    As I said elsewhere, Convert to Comment should not be used for these unless they actually make no attempt to answer the question. If they're redundant, deletion is probably fine (particularly if there are a lot of them on a given question), but C2C sends the wrong message. – Shog9 Apr 24 '13 at 15:48
  • 1
    @Shog9: Yeah, I got it already, that's why I made the edit :) – Manishearth Apr 24 '13 at 15:55

These questions are very useful for repwhoring I've seen. The competition is to enter just the pattern as an answer quickest. Because there is a high chance OP accepts this quick.

Yes, it is sad and not helpful. I tried to give explanations at least to give an answer more value when I answer those. But the reputation is just around the corner, so there is always the driver for the low hanging fruits in that tag.

It's probably good you put it on the meta level to make up ones mind about it.


Just because a answer isn't perfect doesn't mean it has to be deleted or other special actions have to be taken against it.

Of course many, many answers (most of them) could be improved by adding additional or more extensive explanations, examples, external references,... But an answer without all those extras is still better than no answer. If you delete this only slightly useful answer you make the situation worse.

Instead post a better answer yourself, one that adds all the missing information. If you think the original answer isn't useful, downvote it. And if you personally are too lazy to write a big explanation and post that, from where do you take the right to demand additional effort from the guy who posted the "too short" answer?

I also don't see why every regex answer has to be expanded into a regex tutorial. The problem usually isn't the answer, it is that the OP doesn't want to figure out how regexes work and instead asks a question on SO. If someone wants to find out how regexes work, there are plenty of resources to do so.

  • 3
    Just because I don't want to or cannot provide an answer doesn't mean I may not expect those who can and want provide an answer to uphold our quality standards. Also, I disagree that deleting those answers makes the situation worse. The current pattern is way too often ask, copy, paste, repeat. The result is lots and lots of too localized questions that only help that specific OP. We should not encourage this behavior. Of course, asking folks to put an explanation is somewhat more constructive than just deleting answers. Anything that gets the point across that we dont want those anymore. – Gordon Apr 24 '13 at 14:26
  • @Gordon: I don't think deleting answers gets the point across that the questions are bad/lack research effort. The main problem seem to be the questions, rather than the answers. – sth Apr 24 '13 at 14:38
  • yes and no. It's actually two problems. If the question is poor to start with, downvote or closevote of course. Answering these will encourage more bad questions. After all, they got their fish and will come back for more. It's a different thing though if the OP is not one of those lazy OPs. If she wants to actually learn something, then by any means throw her the fishing guide and not just the fish. – Gordon Apr 24 '13 at 14:56
  • 3
    I agree with sth. They're not good answers, but they are answers. I'll stick to downvoting them. – mmyers Apr 24 '13 at 16:13
  • 1
    But an answer without all those extras is still better than no answer. I believe that is a fundamental flaw in your understanding of the problem. Spoonfeeding is, in fact, actively harmful. – Lightness Races in Orbit May 1 '13 at 15:33
  • 1
    it is that the OP doesn't want to figure out how regexes work and instead asks a question on SO Then they misunderstood what SO is for. It's not "make me a regex dot com". – Lightness Races in Orbit May 1 '13 at 15:34
  • @Lightness: The point being made in this meta question isn't that those answers would be too helpful and spoon feed the OP answers, it is claimed that these answers are not helpful enough and because of that should be deleted. I just think that's wrong. Also that SO isn't "make me a regex dot com" only seems to reinforce my point that the real problem usually lies in the question. And removing answers because they are not helpful enough (like suggested in this meta question) seems not like the most straight forward way to fix the bad question problem. – sth May 1 '13 at 16:25
  • 2
    @sth: Spoonfeeding is not defined as "too helpful". – Lightness Races in Orbit May 1 '13 at 16:49

Dear sir,

Kindly provide me with a regular expression that will isolate the price of beaver pelts from the report of commodities arriving on the weekly packet from Hudson Bay.

is, however politely worded, isomorphic to 'plz send me the codez.' Writing regular expressions is just another programming task, and a 'professional or enthusiast' programmer should want to learn how to write a particular regular expression, not just get handed a cup of alphabet soup.

Thus, these question+answer pairs are classic 'broken windows', however useful, through which the help vampires fly.

Ideally, we wouldn't be discussing answers, but rather questions, and promptly closing questions as 'too localized' that ask for idiosyncratic regular expressions in this fashion.

Just as we would for any other question, we'd call for the questioner to tell us what, in particular, they are stuck on, so that an answer could teach, not just stretch out a neck for the bite.

Closing the questions solve part of the problem, but leaves the perverse incentive for people who choose to answer then quickly rather than close it or perhaps edit it to yield a teachable moment and then teach in the answer.

Downvoting these answers, then, seems to best way to make the punishment fit the crime.

  • we already have a policy for these. downvote and close :) – Gordon Apr 24 '13 at 17:35

In contrast to link only answers, regex only answers aren't affected by link rot. As programming languages normally stay backwards compatible, a regex that once worked, will also work in the future.

So as already suggested, extending existing answers is a good way.

  • Blarg, link-only answers are perfectly valid if the link is still operational. They're just low quality, and will probably get downvoted (even if a link was useful and answered the question, I still won't upvote link-only answers because of their quality). Of course, if the link goes bad or if another answer gets posted that covers the same material in the link, then I'd say they're fair game for deletion as then they no longer add anything of value to the question. – Rachel May 7 '13 at 15:27

Are answers that just contain a regex pattern really “good answers”?


  • 3
    -1 Doesn't mean you can just post a single word and not trying to convince the rest of the people that it is no good. – nhahtdh May 1 '13 at 15:30
  • 3
    @nhahtdh: I can do whatever I want. – Lightness Races in Orbit May 1 '13 at 15:32
  • 1
    OK, but what about the resolution? Delete them? Leave them alone? They are definitely not good answer, but you don't suggest what to do with them - which is what this discussion is about. – nhahtdh May 1 '13 at 15:35
  • @nhahtdh: I'm answering the question as posed in the title. Others have gone into greater detail about how to handle such answers. However, I have added my view. – Lightness Races in Orbit May 1 '13 at 15:46

You must log in to answer this question.

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