Possible Duplicate:
No matches with c++11 regex
I was reading this book that covers C++11 and I got to the chapter that talks about Regular Expressions. Everything was working fine for me until I got the part about grouping and referring to \1 whenever I needed to refer back to a group. My code compiles perfectly fine :
#include <iostream>
#include <regex>
#include <string>
int main()
{
try
{
regex r1("<(.*)>.*</\\1>");
bool found = regex_match(string("<tag>value</tag>"),r1);
cout << "Does the string match: ";
cout << boolalpha << found << '\n';
}catch( exception e)
{
cout << e.what() << '\n';
}
return 0;
}
What happens however is I get a segmentation fault (core dumped) message. This little snippet was used directly from the book so I highly doubt this is wrong.
Note: I do compile using -std=c++0x.
Note: I’m using Code::Blocks under Ubuntu 12.04
Any help would be highly appreciated!
Thanks!
libstdc++’s implementation of regex is HILARIOUSLY incomplete.
http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.2011
Head down to section 28, regular expressions. If you’re using libstdc++ (which is almost certain as you’re on ubuntu) then you cannot use regex yet.
It’s a shame, because g++’s toolchain for C++11 is otherwise extremely solid.
You’ll need to use boost for this probably, or another regex library. Or change over the clang (and clang’s libraries) or to MSVC (and their libraries).