For a regex-only solution that matches an odd number of any character (excluding one-character matches):
(.)(?<!\1\1)\1(?:\1\1)*\1(?!\1)
Or a shorter version thanks to Wiktor:
(.)(?<!\1\1)(?:\1\1)+(?!\1)
Demo.
Breakdown:
(.) # First capturing group - matches any character.
(?<!\1\1) # Negative lookbehind - ensures the matched char isn't preceded by the same char.
(?:\1\1) # A non-capturing group that matches two occurrences of
# the same char (at least 3 in total).
+ # Matches between one and unlimited times of the previous group.
(?!\1) # Negative lookahead to make sure no extra occurrence of the char follows.
Demo in C#:
string input = "hjasaaasjasjbbbbbashjasccccccc";
string pattern = @"(.)(?<!\1\1)(?:\1\1)+(?!\1)";
var matches = Regex.Matches(input, pattern);
foreach (Match m in matches)
Console.WriteLine(m.Value);
Output:
aaa
bbbbb
ccccccc
If you want a solution that matches an odd number of any character (including one-character matches):
(.)(?<!\1\1)(?:\1\1)*(?!\1)
Demo.