11

Exhibit A: https://stackoverflow.com/questions/23352186/how-does-b-work

Note that I left a comment stating that http://regex101.com will provide a detailed explanation of each element of his regex. Do we really want to duplicate that resource here?

If it's off-topic, what close reason do we use?

10
  • 1
    An answer expressing your disagreement (whatever it is) would be preferable to a downvote. I'm not even taking a position, really, although I'd be happy to do so if that would clarify.
    – Robert Harvey Mod
    Commented Apr 28, 2014 at 22:31
  • 1
    Ooooo that's really cool. No more will I have to sit there and decipher weird regex!
    – animuson StaffMod
    Commented Apr 28, 2014 at 22:34
  • I don't have an off-topic reason for this but too many of these would seem like clutter. What about a feature-request for a resource page including things like this, jsonlint.com and others? That could be a very valuable page
    – codeMagic
    Commented Apr 28, 2014 at 22:55
  • 5
    @RobertHarvey Don't we have a general regex question now? This one.
    – hichris123
    Commented Apr 28, 2014 at 23:39
  • I don't usually follow regex questions closely, however I was under the impression generic how do I ones were supposed to be closed in support of the canonical ones.
    – Travis J
    Commented Apr 28, 2014 at 23:44
  • @hichris123: I'm wondering if all "How does this C# work" questions could be closed as a duplicate of The C#, One Ring to Rule Them All FAQ question.
    – Robert Harvey Mod
    Commented Apr 28, 2014 at 23:50
  • Meh, I'm not saying that all regex questions should be closed in that, maybe just some of the more basic ones ("How does [insert random regex here] work")? Not sure, I don't think we've really ironed out even what that general regex reference question is supposed to be.
    – hichris123
    Commented Apr 28, 2014 at 23:52
  • Questions that ought to be downvoted and closed as typos are upvoted.
    – devnull
    Commented Apr 29, 2014 at 2:25
  • 4
    Most of these fell to the too localized hammer in the good old times, now we don't really have a good succinct way of expressing that so they just get down voted/close voted into oblivion with no comments why because that is the path of least resistance.
    – user177800
    Commented Apr 29, 2014 at 2:35
  • Anyone who's feeling like a smartass, go ahead and explain - elegantly - how that regex works. Of course it's a good question. Regex is programming literature - there's always room to discuss it. (The fact that a "machine generated" answer exists - so what?)
    – Fattie
    Commented Jun 30, 2014 at 14:00

3 Answers 3

13

Lets look at how most of these questions are answered:

One doesn't need to post an answer for any of these, does one? A reference in the comments might suffice with a vote-to-close and an optional downvote.

Moreover, the bigger point (that you mention in the comments) is that such questions do not really help as those are not searchable.

The tag is usually flooded with extremely low quality questions that we continue to encourage. Our attitude contributes to the problem raised in the following post:

Question quality is dropping on Stack Overflow

I'd prefer to close such questions with a custom message (that could be made more polite):

This questions appears to be off-topic because the explanation of the regex in question can be found at multiple sites. Information about regular exprssions is also available at http://www.regular-expressions.info and wikipedia.

5
  • Hmmm, think I might go for a wander in [regex] with your custom close reason. That question you linked in the comments above made me die a little inside.
    – OGHaza
    Commented May 21, 2014 at 9:26
  • @OGHaza Which comment are you referring to? Using a custom close reason isn't really necessary, one might as well use: ... it lacks sufficient information to diagnose the problem ....
    – devnull
    Commented May 21, 2014 at 9:49
  • Yeah true, I was referring to this question - but I've seen plenty asking the same sort of question. "I have this regex to match a username [a-zA-Z0-9], but I don't want to match capital letters"...
    – OGHaza
    Commented May 21, 2014 at 9:53
  • @OGHaza The specific question was presented as an example because I just ran into it moments before running into this question. That said, utter FAQ is asked in the regex tag (yes, I'd also have answered those on several occasions) giving a feeling that it doesn't really add up to knowledge on the site.
    – devnull
    Commented May 21, 2014 at 9:56
  • I've answered more than my fair share of terrible regex questions so I can hardly sit on a high horse, but I think some basic ability to parse a regex is required for answers to actually be beneficial to the OP (other than as as code writing service). In [regex] I feel most OPs have 0 knowledge going in, once they get an answer they have 0 knowledge of regex + a snippet of code they can use for this one-off problem. All my non-regex answers are in SQL and ok the questions are usually duplicates, but if you ignore that, the questions themselves do at least have some merit.
    – OGHaza
    Commented May 21, 2014 at 10:23
10

Yeah, I think so.

Some regex questions will be too basic and ought to get downvoted or an RTFM answer, but there's something to learn from seeing what confusing regular expressions people encounter in the wild.

Stackoverflow users are also good at deciphering why a regular expression is used rather than just what it is and how it works. For example, I could learn that

/^\s+|\s+$/g

means

1st Alternative: ^\s+
    ^ assert position at start of the string
    \s+ match any white space character [\r\n\t\f ]
        Quantifier: Between one and unlimited times, as many times as possible, giving back as needed [greedy]
2nd Alternative: \s+$
    \s+ match any white space character [\r\n\t\f ]
        Quantifier: Between one and unlimited times, as many times as possible, giving back as needed [greedy]
    $ assert position at end of the string
g modifier: global. All matches (don't return on first match)

But I'd probably be better served by someone pointing out “it matches white space at the front and back of the string.”

3
  • 5
    What do you do about the title? "How does [this specific regex] work" is not very googlable.
    – Robert Harvey Mod
    Commented Apr 28, 2014 at 22:49
  • Oh, my! So you say it's good to have different questions asking what is (1) \s, (2) \s\s, (3) \s{0,1}, (4) \s{1,2}, ... And then smart humans would pitch in the explain what those could imply. Sweet.
    – devnull
    Commented Apr 29, 2014 at 2:01
  • 2
    Flame away on the bad questions in any category. Not all regex questions are good questions. That is different from saying that all regex questions are not good questions.
    – mob
    Commented Apr 29, 2014 at 14:44
2

In my opinion, they are technically on-topic, but should be closed as a duplicate of Reference - What does this regex mean?. AFAIK, that's what that that question was created for.

You must log in to answer this question.

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