Tried solving today's #adventofcode using only regex, and it turns out that it's not easy to match a string containing any character consecutively repeated exactly 2 times (but no more).
For example, I want to match "abccd", but not "abcccd".
It's simple for a single character, e.g. the "c" from the example above:
This uses negative lookbehind and lookahead to make sure the two c's are not preceeded or followed by any other c's.
But if you want to make it generic, e.g. match any letter, you might try using backreferences:
This produces the error: "lookbehind assertion is not fixed length" since the regex engine cannot know how big the backref is.
Another attempt was using the \K delimiter which allows for variable-length lookabehinds by matching anything before it and discarding it. However there is no negative variant of \K so it's of no use here.
Finally, I tried matching the character in the lookbehind, and while this kind of thing works for a positive lookbehind, e.g. this matches any letter preceeded by itself:
It does not work for negative lookbehind. This does not match anything:
Server run by the main developers of the project It is not focused on any particular niche interest - everyone is welcome as long as you follow our code of conduct!