0

Concerning this question:

Regex any character as long as the character is the same

I have a string representing cards in a deck, i.e. 7c9hQsKsAs

Is it possible to use Regex to specify .*x.*x.*x.*x.*x where x would specify any character (c/h/d/s) as long as the character is the same character throughout? This would be used to determine if there was a flush.

This was marked (with some sort of tag super power single vote, I haven't been as active lately so I don't know the term) as a duplicate of:

Have trouble understanding capturing groups and back references

To me this seems like a dubious duplicate. By that logic, literally any question about regex back references would be a duplicate of the target question.

This new question asks how to solve a specific problem, and the answer happens to be back references.

On the contrary, the target question is about understanding and interpreting the function of backreferences when already aware of them.

This seems like a kind of sad use of the dupe-hammer, since it shuts down answers to novel problems, just because the same tool is used to answer the problem. 😞

16
  • 1
    How is the problem novel? I'm seeing a question asking about repeating capture groups, and an answer which explains how they work. I don't disagree that there's not a lot of ceremony in between the two, but objectively, I do see how one answers the other. Supposing then that if this weren't closed as a duplicate, how would you have answered it?
    – Makoto
    Commented Feb 21, 2019 at 22:19
  • (By the way, I really am trying to be objective here - I would like to have this conversation. For there to be consensus, I have to understand your perspective; don't think that I'm trying to shut you out or anything silly like that...)
    – Makoto
    Commented Feb 21, 2019 at 22:23
  • @Makoto Thanks for the good faith. My point is that although you can say to OP "you'd use capturing groups, learn about them here [link]", that's not the same as saying that OP asked the same question. It's a novel question because OP could never have known this was a duplicate unless they already knew the answer to their own question.
    – Nicole
    Commented Feb 21, 2019 at 22:31
  • Fair enough - I see "novel" in a different light, referring to the site itself. Sure, the OP may have never heard of it, but the question likely has been posed before, which would necessitate more searching for the topic material. And granted - the OP may have never heard of that topic material. I don't feel like their lack of exposure to repeating capture groups makes the question about repeating capture groups "novel" on the site.
    – Makoto
    Commented Feb 21, 2019 at 22:32
  • 6
    @Nicole We don't close a question as a duplicate as a way of saying, "You should have known that you should have looked at this before asking this question." It's a way of saying, "This is where you can go to get your answer." Whether they could have found the duplicate on their own or not doesn't affect whether or not it is a duplicate. It might affect how useful the question is, which is an unrelated issue.
    – Servy
    Commented Feb 21, 2019 at 22:32
  • (Oh yeah - see, I did add in parentheses that I was interested in the conversation - strangely I'm getting pinned as the closer and downvoter. Today hasn't been my day.)
    – Makoto
    Commented Feb 21, 2019 at 22:33
  • @Makoto To be specific about this case and why it felt novel to me. Although I'm aware of backreferences, I had never thought of them being used for a problem like this before. So, to me, it was a novel problem even though I knew of them and answered the question about it. To me duplicate means "THIS question has been asked before" — it should substantially match the basis of the question (it doesn't) and the answers should match (they don't, since the dupe explains back references instead of using them to solve a problem).
    – Nicole
    Commented Feb 21, 2019 at 22:35
  • @Makoto I don't believe you to be the downvoter and I know the closer was Wiktor StribiĆŒew — I believe they are the one who downvoted this question.
    – Nicole
    Commented Feb 21, 2019 at 22:36
  • 2
    @Nicole How do you know the closer is the one who downvoted? I'm pretty sure votes are confidential... Assuming bad intent is something we're trying to reduce on meta. Commented Feb 21, 2019 at 22:36
  • @HereticMonkey I don't, I realize I am making an assumption. The downvote happened shortly after I replied to them and linked to this question.
    – Nicole
    Commented Feb 21, 2019 at 22:37
  • I see your point @Nicole, but that's not quite how duplicates work. I'll see if I can find some reference material here on Meta in regards to that...
    – Makoto
    Commented Feb 21, 2019 at 22:38
  • Uber-meta reference: meta.stackexchange.com/a/74083/175248
    – Makoto
    Commented Feb 21, 2019 at 22:40
  • And ironically, since we do have material to cover this, I've closed this as a duplicate. If you do want to talk about why the question should be reopened and why it isn't a dupe, I'd say you want to post a new question asking about that specifically.
    – Makoto
    Commented Feb 21, 2019 at 22:40
  • @Makoto I think I had read that link a long time ago. I think the top voted answer is actually arguing my point, isn't it?
    – Nicole
    Commented Feb 21, 2019 at 22:41
  • @Makoto Can you help me understand how that link argues your point instead of mine? It is saying that it should be an exact duplicate, not just have similar answers?
    – Nicole
    Commented Feb 21, 2019 at 22:42

1 Answer 1

8

How broadly are similarities considered duplicates?

Not broadly.

My rule of thumb is, if two questions have the same answer, then they are duplicates.

Pedants love to point out exceptions to this rule. Oh, they will say, what if one question asks "What is 22 + 20?" and another question asks "What is the answer to life, the universe, and everything?" Both of those questions would have the same answer—42—but are they duplicates? Um, no. Rules of thumb are not replacements for using your brain.

But this "same answer" rule of thumb is surprisingly accurate, and very powerful. It means that the questions don't have to be identical, as long as they cover the same ground and have the same answers. This means that, for example, a question about using a feature in a particular framework/API in the context of Delphi can be a duplicate of a question about using that same feature in the context of C. The framework/API feature is the same; it doesn't matter whether you're calling it from C or Delphi. We only need a separate question if there are nuances of invoking that feature from Delphi that don't apply to C. And a Delphi expert would know that; that's why we give gold tag badge holders the ability to single-handedly mark duplicates.

Regex is a slightly unusual case, though, because most of the "questions" we get about regular expressions are "Can someone write me a regex that does the following?", which is only formally a question. And usually, they're not even phrased in the form of questions. They're presented as problem statements. That tends to get tiresome for the experts whom we have answering regular expressions questions, so they will look for a canonical question to mark those "give-me-teh-codez" questions as a duplicate of.

This works well in most cases. The canonical questions generally have high-quality answers, and this is consistent with our mission of creating a library of high-quality answers to specific programming problems.

It could be called the "teach a person to a fish" approach, which is a lot more reusable and versatile. Plenty of other people in the future are going to have problems that can be solved with the use of back references, and will therefore benefit from comprehensive answers explaining how to leverage them. A lot fewer people are going to have a need to write exactly the same regex as the person who happened to ask this particular question.

It can also be seen as merely a practical way of dealing with an influx of tiring and exhausting questions that all cover exactly the same ground. It's the same reason we have a canonical "What is a NullReferenceException, and how do I debug it?" question: it frees the experts from having to write a bunch of hyper-specific answers to a hundred different people's unique problems that are all broadly the same.

It doesn't hold the reader's hand, but it does give them useful information and ultimately leads them to the solution.

It also isn't perfect, and in some cases, isn't appropriate. This is, again, why we give gold tag badge holders the ability to single-handedly re-open questions that are marked as duplicates. If you see something unique in a question that you feel—in your expert opinion—is not adequately addressed by the duplicate, then you should re-open it and post an answer highlighting those differences.

TL;DR: Marking a question as a duplicate is ultimately a judgment call, and that's why we require either a consensus (5 trusted users) or a proven expert (gold tag badge holder) to make the call.

6
  • 1
    Surely there are dupes on this very matter out there which cover the same ground as your response...
    – Makoto
    Commented Feb 21, 2019 at 22:54
  • 6
    Surely, but I needed the rep.
    – Cody Gray Mod
    Commented Feb 21, 2019 at 22:54
  • 5
    I both love and hate your comment. Thank you.
    – Makoto
    Commented Feb 21, 2019 at 22:55
  • 3
    I wish to award this answer a bounty of all my reps. Mostly for that paragraph about "20+22" and "life, the universe, and everything".
    – jscs
    Commented Feb 21, 2019 at 22:56
  • @CodyGray "then you should re-open it and post an answer highlighting those difference" - I thought the guidance is (or at least was) to make sure question is edited to clarify why it is unique and only then re-open... Could you please clarify that? Commented Feb 21, 2019 at 22:59
  • @AlexeiLevenkov You would only need to edit the question if the question didn't already clearly articulate what is needed that's not covered in the duplicate. Which is most of the time, but not all of the time.
    – Servy
    Commented Feb 21, 2019 at 23:00

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