Regular expressions of misunderstanding or just broken implementation?

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?

+1
source share
1 answer

As you can see from C ++ - 0x the status of libstdC ++ support for regular expressions is incomplete. In particular, match_results are not completed. Iterators do not even start.

Volunteers are welcome; -)

[EDIT] [In gcc-4.9] 2 will be fully supported.

+3
source

Source: https://habr.com/ru/post/1439995/


All Articles