Two things:
- Your string
"10;20;30;40;"
is only defined in thematch_regex
call. Ansmatch
, as opposed tocmatch
, expects the string (as in, the one created bystring()
) to still be alive by the time you want to access it. - Your current regex doesn't match (at least not on my system). It tries to match the whole string. Adding a .* at the end (and start, but that's not necessary in your case) should fix it, as would letting the whole thing repeat (with
R"((stuff)*)"
)
Working code (but couldn't try it on gcc):
regex rx{ R"(\d*(\.\d*)?;.*)", regex_constants::ECMAScript };
smatch m;
string s("10;20;30;40;");
if (regex_match(s, m, rx))
{
cout << m[0];
}
Don't know if that will fix your particular error - I'm afraid KitsuneYMG is right on that count - but it shouldn't hurt to try.