Fortunately .NET regular expressions are capable of handling infinite lookbehinds. What you need could be achieved using the following regex:
((?>(?(2)(?=\2))(.)\2)+)(?<!\2\1)(?!\2)
See live demo here
Regex breakdown:
(
Start of capturing group #1
(?>
Start of non-capturing group (atomic)
(?(2)
If capturing group #2 is set
(?=\2)
Next character should be it
)
End f conditional
(.)\2
Match and capture a character and match it again (even number)
)+
Repeat as much as possible, at least once
)
End of capturing group #1
(?<!\2\1)
Here is the trick. The lookbehind tells engine that the immediate preceding character that comes earlier than what we matched so far shouldn't be the same character stored in capturing group #2
(?!\2)
Next character shouldn't be the same as the character stored in capturing group #2
UPDATE:
So you can do following code in C# to get all even sequences chars in string by Regex
with no any other operators (pure Regex).
var allEvenSequences = Regex.Matches("aaabbashasccddee", @"((?>(?(2)(?=\2))(.)\2)+)(?<!\2\1)(?!\2)").Cast<Match>().ToList();
Also if you want to make [bb],[cc],[dd],[ee]
then you can join that sequence array:
string strEvenSequences = string.Join(",", allEvenSequence.Select(x => $"[{x}]").ToArray());
//strEvenSequences will be [bb],[cc],[dd],[ee]