It is supposed to match "abababab" since "ab" is repeated more than two times consecutively but the code isn't printing any output.
Is there some other trick in using regex in C++.
I tried with other languages and it works just fine.
#include<bits/stdc++.h>
int main(){
std::string s ("xaxababababaxax");
std::smatch m;
std::regex e ("(.+)\1\1+");
while (std::regex_search (s,m,e)) {
for (auto x:m) std::cout << x << " ";
std::cout << std::endl;
s = m.suffix().str();
}
return 0;
}
xaas well..(.+)just greedy and matches the whole string? Therefore the\1does not make any sense<bits/...>, it's not portable and you have no guarantee it will work tomorrow. Also, you may need to upgrade gcc to the latest and greatest 5.x version, earlier ones don't have a working regexp implementation.R"((.+)\1\1+)"or escape the backslashes"(.+)\\1\\1+".+match successively less until the\1matches. It's a fairly common idiom in regex.