Strange error - std :: regex matches only the first two lines

Today I encountered an unusual error in my application. I tested it like 2 hours and did not find a solution. Maybe you can help me solve this problem. So here it is:

#include <iostream> #include <regex> #include <vector> int main() { std::regex reg("rmvb|avi|rm|mp4|256"); std::vector<std::string> ext{"rmvb", "avi", "rm", "mp4", "256", "null"}; for (int i = 0; i < 6; i++) { std::cout << ext[i] << "\t" << std::boolalpha << std::regex_match(ext[i], reg) << std::endl; } return 0; } 

Output:

 rmvb true avi true rm false mp4 false 256 false null false 

It seems that the pattern is discarded after the second element - no matter what order I choose (I tried to change them because I thought that the numbers could cause this error, but it is not). Now I have no idea what is going on.

I am using gcc version 4.6.3 (Debian 4.6.3-1).

+1
c ++ linux regex c ++ 11
source share
1 answer

The regex library is basically not yet implemented in libstC ++ (cf. status page ). This may be a mistake or simply the result of its implementation. I would suggest using Boost.Regex as a replacement.

+3
source share

All Articles