Is this C++11 regex error me or the compiler?

前端 未结 3 1182
闹比i
闹比i 2020-11-27 17:34

OK, this isn\'t the original program I had this problem in, but I duplicated it in a much smaller one. Very simple problem.

main.cpp:

#include 

        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-27 18:11

    Update: is now implemented and released in GCC 4.9.0


    Old answer:

    ECMAScript syntax accepts [0-9], \s, \w, etc, see ECMA-262 (15.10). Here's an example with boost::regex that also uses the ECMAScript syntax by default:

    #include 
    
    int main(int argc, char* argv[]) {
      using namespace boost;
      regex e("[0-9]");
      return argc > 1 ? !regex_match(argv[1], e) : 2;
    }
    

    It works:

    $ g++ -std=c++0x *.cc -lboost_regex && ./a.out 1
    

    According to the C++11 standard (28.8.2) basic_regex() uses regex_constants::ECMAScript flag by default so it must understand this syntax.

    Is this C++11 regex error me or the compiler?

    gcc-4.6.1 doesn't support c++11 regular expressions (28.13).

提交回复
热议问题