Following What does std::match_results::size return? I tried to get this simple string to match
#include <regex>
using namespace std;
void main() {
stringstream ss(
"<tag1 abc = \"Test ABC\" def = \"Test DEF\">"); string line;
regex re_open_tag("<([[:alnum:]]+)( \\w* = \\\"[\\w|\\s]*\\\")*>");
while (getline(ss, line, '\n')) {
for (auto i = sregex_iterator(begin(line), end(line), re_open_tag); i != sregex_iterator();
i++) {
auto &match = *i;
for (auto i = 0UL; i < match.size(); i++) printf("Match:%s\n", match[i].str().c_str());
}
}
}
It successfully matches the string as a whole but I get the following output
Match:<tag1 abc = "Test ABC" def = "Test DEF">
Match:tag1
Match: def = "Hello world"
Where did abc=... go from the set of matches. The std::sub_matches
number 3 which is 1 less than what I'd expect.