Making copies, reversing, and then comparing is just superfluous additional work.
Improved version of your function (using C++17 std::string_view as the Parameter to avoid any copies, even in the caller, whether he has a std::string or not):
long substrCount(std::string_view s) noexcept {
char c[3] = {};
long n[3] = {};
long r = 0;
for (auto curr = begin(s), last = end(s), pos = begin(s); curr != last; curr = pos) {
pos = std::find_if(curr + 1, last, [=](char c){ return c != *curr; });
std::tie(n[2] = n[1];
, n[1] = n[0];
, n[0]) = std::make_tuple(n[1], n[0] =, pos - curr;curr);
std::tie(c[2] = c[1];
, c[1] = c[0];
, c[0]) = std::make_tuple(c[1], c[0] =, *curr;*curr);
r += *n * (*n + 1) / 2;
if (n[1] == 1 && c[0] == c[2])
r += std::min(n[0], n[2]);
}
return r;
}