I tried a very simple use of regex_search and cannot understand why I am not getting a match:
Alas, gcc-C ++ 0x-implementation 4.5 does not seem to work, I get an error here .
But here is my attempt to gcc-4.7.0, quite simple:
#include <iostream> #include <string> #include <regex> using namespace std; int main () { regex rxWorld("world"); const string text = "hello world!"; const auto t0 = text.cbegin(); smatch match; const bool ok = regex_search(text, match, rxWorld); /* ... */ }
I think I should get ok==true and something in match . For this, I gave an example to a very simple regular expression. At first I tried to complicate things a bit.
But when printing the code in /* ... */ it says otherwise:
cout << " text:'" << text << "' ok:" << ok << " size:" << match.size(); cout << " pos:" << match.position() << " len:"<< match.length(); for(const auto& sub : match) { cout << " ["<<(sub.first-t0)<<".."<<(sub.second-t0) << ":"<<sub.matched << "'"<<sub.str() << "']"; } cout << endl;
Output:
$ ./regex-search-01.x text:'hello world!' ok:0 size:0 pos:-1 len:0
Update: I also tried regex_search(t0, text.cend(), match, rxWorld) and const char* text , no changes. `
Is my understanding of regex_search wrong? I am completely puzzled. Or is it just gcc?
source share