std::cmatch res;
std::string str = "<h2>I'm a piece of text</h2>";
std::regex rx("<h(.)>([^<]+)");
std::regex_search(str.c_str(), res, rx);
std::cout << res[1] << ". " << res[2] << "\n";
This simple piece of code should work? right?
Apparently it doesn’t:
terminate called after throwing an instance of 'std::regex_error'
what(): regex_error
Aborted
Compiler( gcc 4.7.0 ) bug or am I missing something?
The brackets in the regex seem to be causing the problem. See this SO thread for more details and possible workarounds.
Also (from the same thread), gcc version 4.6.1 had only partial support for
std::regex, I don’t know if it has been fixed in version 4.7.0 yet