27

Looking for community feedback on why my question today was closed as a dupe: Why does regex lookahead and lookbehind behave the same with anchor ^

In fact, I did find the answer I was looking for myself on the dupe target, before it was closed, but it is a very different question and it seems to be merely an aside that Wiktor Stribiżew happens to explain the counterintuitive behaviour I was asking about in one of the 7 answers.

After a poking around on meta I found this highly rated meta answer which indicates that two questions sharing a common answer are not necessarily dupes. In light of this, and because the two questions ask such different things, I opted to repost the quote with citation and answer my own question.

Side note: I notice that the dupe message doesn't actually show the close voter's name in this case even though that info is available in the edit timeline. Is this new behaviour? Even with a single closer I expect to see a message like:

Closed 2 hours ago by John Doe
(List of close voters is only viewable by users with the close/reopen votes privilege)

12
  • 5
    Usually, if the answer is the same then the question can be closed as a duplicate even though it might be a completely different question. Whatever we can do to reduce duplication.
    – Dharman Mod
    Commented Oct 9 at 21:09
  • 7
    We don't really need duplicates of identical questions. The purpose of it is to mark similar questions with same answers so that the traffic can be redirected there. If the questions are the same then why keep both?
    – Dharman Mod
    Commented Oct 9 at 21:10
  • 5
    Yes, but the answer is not the same. Question A: How can I do X, Question B: Why does this one particular approach to doing X work the way it does? It is perfectly possible to answer (A) without addressing (B) in the least. Furthermore, I don't see how (B) is even a good signpost for (A) Commented Oct 9 at 21:10
  • 8
    By our current standards your answer should be deleted because it doesn't contain any original content. And you see, this is where the problem lies. We don't have the perfect solution for duplicate answers. The best we can do is close as a duplicate.
    – Dharman Mod
    Commented Oct 9 at 21:19
  • 48
    If you spend some time on the regex tag (and have the rep to see the closer) you will see a large number get closed as duplicates from a single user. On the one hand, they are working hard for the community, but on the other, I often have to squint really hard to see the connection with the duplicate.
    – Mark
    Commented Oct 9 at 21:44
  • 1
    I wouldn't be surprised to find that SO doesn't show you the close-voters of your questions to prevent reprisals even if you have sufficient rep to see the closers of other people's questions. Commented Oct 10 at 0:22
  • 6
    A bit irrelevant, but I wouldn't be surprised if your question turns out to have been asked before, and the correct dupe is simply too hard to find. Given that most of the 260k+ questions in the regex tag are about very specific problems, those that are more generic (like this one) are basically buried; not to mention, regex questions are naturally not very searchable.
    – InSync
    Commented Oct 10 at 6:49
  • 1
    @user4581301 I'm almost certain that's the way it works. You never get to see the close voters on your own question, no matter how much rep you have. Commented Oct 10 at 12:24
  • 1
    "After a poking around on meta I found this highly rated meta answer" - no, it's decently rated, it's only one answer (versus how many answers that state otherwise?) and it's from 2015. Times do change. Status quo is to not want to really have to think about it, and that matches with "if there is an answer which answers all, it's a duplicate".
    – Gimby
    Commented Oct 10 at 13:52
  • 14
    Excellent! All I need to do is make 2 questions one answered Yes and the other No and I can close almost anything as a duplicate! Muhuhahahahahahahaha! Commented Oct 10 at 14:21
  • 2
    "I did find the answer I was looking for myself on the dupe target," - The fact an answer to the duplicate question, answered your question, is the reason your question was a duplicate of the question. A question becomes a duplicate, when an existing answer to a different question, answers the question that was asked. The wording of the existing question is often not even a consideration, it's entirely the answer to the existing question, that determins if a different question is a duplicate or not. Commented Oct 10 at 14:44
  • 2
    Regarding Sidenote: meta.stackexchange.com/questions/385961/… @MarkRansom That's incorrect. Not only you, but even anonymous users.
    – TheMaster
    Commented Oct 11 at 0:13

2 Answers 2

59

I'm not going to unilaterally reverse the community here (without consensus on meta), but...

This isn't a duplicate. It's a completely different (though related) question.

An answer to this question would not be suitable for answering the target question (which it should be, because someone who wants to post a better explanation should be able to post one). Further, six of the seven answers on the target, including the overwhelmingly top-voted one, don't address this question at all. And the one that does address it includes the answer as, essentially, an explanation of why the answer works, not the answer itself.

Consider another example1 that's arguably even closer to the line (because at least all answers to the latter would address the former): "How do I really uninstall McAfee Antivirus?"2 and "How do I perform a clean reinstall of Windows?" may have the same answer, but they're not duplicates, because they're asking how to do very different things.


1 It wouldn't be on-topic here because it's not about programming, but it conveys the conceptual point.
2 This is mostly a joke about McAfee's reputation for being difficult to uninstall; if you want a serious example, go with "How do I remove spyware on Windows with 100% certainty?" instead.

5
  • 5
    So now instead of an "incorrect" dupe, what we have is an answer by OP that is a copypasta and link to the relevant answer from the "incorrect" dupe. How, exactly, is that any better?
    – Ian Kemp
    Commented Oct 10 at 13:02
  • 5
    Note that I am not arguing that the linked question should be closed; I am noting that regardless of which way we skin this cat, there is unwanted duplication. I don't know the right answer.
    – Ian Kemp
    Commented Oct 10 at 13:29
  • 1
    @IanKemp - there doesn't have to be. I think Barmar's answer is just fine so I deleted my answer and added it as a comment. Is that an improvement? Commented Oct 10 at 19:59
  • 18
    It's not "unwanted duplication" if the answer links to another Q&A. That linkage connects the dots in a way that is similar to closing the question as a duplicate, except that some explanation can be provided of what the relationship is between the two questions. This is important in a case where one answer to another question incidentally includes the answer to a particular question. Those questions are not duplicates, because the answers do not all apply. But you are right that it is better to have the dots connected, which is what links have accomplished since the birth of the web.
    – Cody Gray Mod
    Commented Oct 10 at 22:49
  • 4
    Ah meta. So now we have an answer which says "no very clearly not a dupe" and an answer which says "clearly a dupe" :) And I upvote both, because this answer represents an amount of effort I would like to see be put into dupe closure reasoning, and Karl's answer more represents reality and what you can expect to happen.
    – Gimby
    Commented Oct 11 at 8:46
8

The answer that you were asking about was on a question that is very clearly a duplicate (and I just cast a close vote), and your reason for wondering about why the code works, is very clearly motivated by that question. The linked duplicate is a higher quality explanation of the how-to problem, which includes (thanks to Wiktor Stribiżew's answer) an explanation of why the techniques work (briefly: the beginning-of-text anchor can indeed be found both "ahead of" and "behind" the beginning of any given text, precisely because it's zero width - there isn't any "look-at" assertion for zero-width patterns, so you use either lookahead or lookbehind and they both work).

That definitely meets our standards for duplicate closure. In general, if you think an existing answer on an existing question needs clarification or elaboration, you should normally comment, or consider offering a bounty for the question to get a better answer. Asking a new question is only appropriate if it can stand on its own.

Aside from that, you would be expected to present your reasoning explicitly. "It seems that both of these patterns (negative lookahead and negative lookbehind) will match..." - okay, so do you expect one of them to match, but not the other? Which one? Do you expect neither to match? In each case (and why aren't these separate questions, then?) - if you disagree that it should match, what is your reasoning? "In other words, they behave as expected below, where only the second pattern (positive lookbehind)" - why should that inform your expectations in the ^ case? What's your mental model, going into the question, for lookarounds? Like, suppose I say that the string X- does not contain a - at a position where X can be found (since, at that position, there's - instead), but the string - does contain - at a position where the beginning of the string can be found. Is that confusing? Why? If it isn't (or you can't explain why), there isn't an answerable, separate question there.

3
  • 2
    Thanks. Indeed if the question you mentioned had been closed as a dupe beforehand, I would have seen Wiktor's answer earlier on and never posted my question to begin with. Fortunately his answer on the dupe target exists and does explain things quite well. I was on the fence about closing mine when I first found it so I appreciate the feedback. Commented Oct 10 at 2:44
  • 2
    I agree with this answer. The fact that the exact same answer addresses both questions means that the newer one is objectively a duplicate under the current standards, and closure with the link to the target is the correct action
    – vbnet3d
    Commented Oct 10 at 15:21
  • 7
    If there are good answers that don't address one of the two question, it's not considered duplicates. This goes all the way back to the rule of thumb: all answers to A should also be answers to B and viceversa.
    – Braiam
    Commented Oct 11 at 13:38

You must log in to answer this question.

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