// Example program
#include <iostream>
#include <string>
#include <regex>
int main()
{
std::string strr("1.0.0.0029.443");
std::regex rgx("([0-9])");
std::smatch match;
if (std::regex_search(strr, match, rgx)) {
for(int i=0;i<match.size();i++)
std::cout << match[i] << std::endl;
}
}
this program should write
1
0
0
0
0
2
9
4
4
3
but it writes
1
1
checked it here http://cpp.sh/ and on visual studio, both same results.
Why does it find only 2 matches and why are they same?
As I understand from answers here, regex search stops at first match and match variable holds the necessary (sub?)string value to continue(by repeating) for other matches. Also since it stops at first match, ()
charachters are used only for sub-matches within the result.