I'm trying to extract all numbers (positive and negative) with 4 to 5 digits from a string. To do so, I'm using the following code:
#include <iostream>
#include <regex>
#include <string>
int main() {
std::string test_string("S: 0 2 -1500 -1500 0 -10000 10000");
std::smatch match_results;
std::regex rgx("-?[0-9]{4,5}");
std::regex_search(test_string,match_results,rgx);
std::cout<<match_results.str(0)<<' '<<match_results.str(1)<<' '<<std::endl;
return 0;
}
I would expect this code to output
-1500 -1500
Instead the output is only
-1500
Outputting the 3rd and 4th match doesn't work either.
Testing the regular expresion on the exact same teststring on regex101.com yields all for numbers with more than 3 digits.
What am I doing wrong here?