1

I have the following easy example: where <regex> library is used to search "llo" in "hello world".

#include <regex>
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
    cout << boolalpha;
    regex rgx("llo");
    cmatch result;

    cout << regex_search("hello world", result, rgx) << endl;
    cout << "Matched: " << result.str() << endl;
    return 0;
}

I compile it with "gcc version 4.7.1" with the following command:

c++ regex2.cpp -o regex2 -std=c++11

And the result is:

false
Matched: 

So, what is supposed I am doing wrong? Since it compiles, can I assume that c++11 is able on my computer and therefore library is able too?

Sincerely thanks!

1 Answers1

3

No, std::regex is not fully implemented in the standard library implementation that comes with GCC 4.7.1.

Full support for <regex> will be released with GCC 4.9 later this year.

See this: http://gcc.gnu.org/gcc-4.9/changes.html

In the meantime, I recommend <boost/regex.hpp> using similar syntax.

#include <boost/regex.hpp>

#include <iostream>
#include <string>

int main() {
    std::cout << std::boolalpha;
    boost::regex rgx("llo");
    boost::cmatch result;

    std::cout << boost::regex_search("hello world", result, rgx) << std::endl;
    std::cout << "Matched: " << result.str() << std::endl;
}
Felix Glas
  • 15,065
  • 7
  • 53
  • 82