2

I can not seem to get the c++11 regex functions to work with even the most basic code. I must be missing something very basic, because this quick code keeps printing "No Match!" no matter what pattern I use.

std::string value = "foobar" ;
std::string pattern = "o" ;

std::regex re(pattern) ;
if (std::regex_search(value, re)) {
    std::cout << "Matched!" << std::endl ;
} else {
    std::cout << "No Match!" << std::endl ;
}

If it matters somehow, I compile (and get no errors) with

g++ -Wall -std=c++11 -o test test.cpp

1 Answers1

1

Standard C++11 regular expression are not yet implemented in g++.

See http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.2011

It's not a "bug" in the sense of a mistake in the code... the only mistake is probably not breaking compile time with a message when seeing #include <regex>.

6502
  • 112,025
  • 15
  • 165
  • 265
  • 3
    No. GCC regular expressions don’t work at all. Any apparently working code is pure coincidence. – Konrad Rudolph Sep 11 '13 at 19:34
  • That's some serious bug. Wow. Any idea when it's going to be fixed? Or am I using an old version and it's already been fixed? –  Sep 11 '13 at 19:35
  • @ADCoon It’s not a bug, per se. The `` header is simply not yet implemented in GCC’s version of the standard library. They shouldn’t have shipped half-empty stubs but there you go. – Konrad Rudolph Sep 11 '13 at 19:36
  • @KonradRudolph I guess I'll have to wait or use Boost until they fix it. Annoying, though. –  Sep 11 '13 at 19:42