Here's my code:
int main()
{
string s = "abc1010101bca10";
int c = 0;
string subject(s);
try {
regex re("10+1");
sregex_iterator next(subject.begin(), subject.end(), re);
sregex_iterator end;
while (next != end) {
smatch match = *next;
cout << match.str() << "\n";
c++;
next++;
}
}
catch (std::regex_error& e) {
cout << "Error in regex\n";
}
cout << c << "\n";
return 0;
}
I am trying to find the occurrence of 1{0}+1 in my string.
For input : abc1010101bca10
Output count should be 3 but above code gives it as 2.
I think sregex_iterator
causing problem here as it directly skips matched string.
Current output:
101
101
2
It should be: 101 101 101 3
Please let me know, where I am going wrong.