6

(Sorry for the terrible pun.)

There are quite a few highly-upvoted questions on the topic of matching overlapping strings with :

If I'm not terribly mistaken, the reference mentions none of them. Which should be chosen and added to the reference as the canonical question?

12
  • 6
    So you want a overlapping question?
    – Cerbrus
    Sep 4 at 10:04
  • 2
    According to the answers to the linked questions, the "overlapping" match is language-specific: regex libraries in different programming languages provide their own way for perform such match. In such case, questions about different languages should definitely NOT refer to the same canonical. Moreover, I am not sure that it is a good way to discuss canonicals for different languages in the single meta post.
    – Tsyvarev
    Sep 4 at 10:08
  • 1
    @Tsyvarev An honest question: Which answer(s) said that? I'm trying to find the best post on the topic to add to the regex reference, but I'm not sure which one is best and need some help. All of them has at least one answer which recommends wrapping the original expression inside (?=( )) or a variance thereof.
    – InSync
    Sep 4 at 10:39
  • 7
    E.g. a "Pythonic" question has highly upvoted answer about using third-party library. There are also answers about combining non-lookahead regex with iterations, and those iterations are written definitely different in the different languages. At least, the very example of using lookahead regex differs, as different languages has different ... "words" for express same things.
    – Tsyvarev
    Sep 4 at 11:04
  • 1
    I think this question should be chosen as a canonical: its most upvoted answer explains both the lookahead and manual iteration approaches. Maybe additionally mention possibility of this functional being available in some libraries with link to answer to python question talking about regex module (and libraries in other languages that provide this if you know more).
    – markalex
    Sep 4 at 11:17
  • 4
    @markalex: Imagine someone (e.g. me) asks about overlapping match in Python, and you point me (via "duplicate" mark) to the Javascript question. I open that question... and I don't understand every answer because their examples are written in the language I am not familiar with. I would think: what a useless link/site it is. Of course, you may additionally point me to the question about Python. I would found that Python question useful... and I would wonder: why that Javascript reference is ever needed in my case.
    – Tsyvarev
    Sep 4 at 11:34
  • 1
    @Tsyvarev, finding overlapping matches is rather agnostic: you use (?=(mypattern)), or manually iterate through string and apply your pattern from every position. Do you really think this answer must be repeated for every language?
    – markalex
    Sep 4 at 11:42
  • 9
    "Do you really think this answer must be repeated for every language?" - Yes, I really think that these answers (lookahead and iterate) should be repeated for every language which support them. E.g. in CMake regex engine simply doesn't support lookahead. Should every reader of an answer check, whether suggested solution is supported for their programming language? Or should every answer be accompanied with the exhaustive list of all languages which support it?
    – Tsyvarev
    Sep 4 at 12:24
  • 8
    "finding overlapping matches is rather agnostic" - There is nearly no such thing like "language-agnostic regular expressions": every programming language implements regex in its own way. The only well-known regex standard I am aware of is POSIX. And they said that lookahead is not part of that standard. I hardly can imagine a question about "language-agnostic regex" which could be useful as a duplicate target for questions in different languages.
    – Tsyvarev
    Sep 4 at 12:39
  • Given that the reference question already makes provision for specific programming languages, IMO it would be appropriate to add all of these to that question under "Common Tasks".
    – Ian Kemp
    Sep 4 at 12:58
  • "Sorry for the terrible pun" - why? They're traditional. Sep 4 at 15:08
  • 4
    @KarlKnechtel I know about the tradition; I just don't think it was good :)
    – InSync
    Sep 4 at 15:43

1 Answer 1

3

I ended up adding three posts to the reference:

The first explains the (?=( ) trick, the second shows a workaround by manually modifying the .lastIndex property (), the third makes use of a third-party library which supports overlapping matches natively ().

Thanks to @markalex and @Tsyvarev for their suggestions.

You must log in to answer this question.

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