Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No matches with c++11 regex [duplicate]

Tags:

c++

regex

c++11

Why does this find no matches in g++ (Debian 4.6.3-1) 4.6.3 or clang version 3.2 (trunk 159457)

#include <iostream>
#include <string>
#include <regex>

using namespace std;

int main()
{
    string line("test");
    regex pattern("test",regex_constants::grep);
    smatch result;

    bool ret(false);
    ret = regex_search(line,result,pattern);  
    cout <<  boolalpha << ret << endl;
    cout <<  result.size() << endl;
    return 0 ;
}

output

false
0
like image 446
user1385705 Avatar asked Jun 29 '12 22:06

user1385705


1 Answers

Because <regex> is not yet implemented in libstdc++, as documented here (§28).

For now, use Boost.Xpressive or Boost.Regex instead.

like image 178
ildjarn Avatar answered Oct 07 '22 20:10

ildjarn