I’m trying to utilize the ‘TR1’ regular expression extensions for some C++ string parsing.
I’ve read that the <regex> header and namespace std::tr1 are required for this
I can compile with the <regex> header present(though it forces me to use either the flag, -std=c++0x or -std=gnu++0x)
However, when I attempt to use the std::tr1 namespace in my program, compiling fails with message that tr1 “is not a namespace name”. I cant do things like,
std::tr1::regex rx("mypattern");
I’ve read that TR1 regular expressions have been supported since gcc 4.3.0. I’m using g++ through gcc 4.4.5.
Am I missing something?
g++ 4.7 doesn’t implement regular expressions yet.
But despite that fact, in C++11
regexhas been moved from the namespacestd::tr1tostd. So, instead ofstd::tr1::regex, you should writestd::regex:I don’t know for which g++ versions before 4.7 this applies, too. But this ideone example compiles fine with g++ 4.7. However, remember that the regex implementation isn’t implemented in this compiler version.