Suppose I would like to do extract the contents of matching curly braces using C++11 regex. So, for example, {foo}
would match successfully and I could the use the match_result
to extract the contents. It seems simple, but the following code does not quite do what I wish
std::string foo("{foo}");
std::regex r("\\{(.*)\\}");
std::smatch m;
bool result = regex_match(foo, m, r); // result returns true
cout << m[0] << endl; // prints: {foo}
cout << m[1] << endl; // prints: {foo} instead of just foo as I would expect
Now shouldn't m[1]
return just foo
without the braces given that it is the first capture group?
EDIT: An essential piece of information for this question is that the compiler I'm using is GCC 4.6.3 (which currently is the latest repository version in Ubuntu 12.04 LTS). The answer identifies precisely how poor the support for regex in GCC is.